asyncio will be running by default with tornado 5
See original GitHub issueWhen tornado 5 is released, which is scheduled to be this month, the tornado ioloop will run on asyncio by default. For the most part, this is nice because asyncio will always be running (#9166), but it’s also tricky because simple cells like this that assume asyncio isn’t running will stop working:
loop = asyncio.get_event_loop()
# will fail because loop is already running:
loop.run_until_complete(asyncio.sleep(1))
Without something like #10390, there won’t be an easy way that I can see for users to run asyncio code in IPython, other than putting them in a background thread where they can run it in an eventloop:
aio_pool = ThreadPoolExecutor(1)
def init_loop():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
return loop
aio_loop = aio_pool.submit(init_loop).result()
async def mycoro():
await asyncio.sleep(1)
return 5
result = aio_pool.submit(lambda : aio_loop.run_until_complete(mycoro())).result()
and #10390 still needs to handle the fact that asyncio will be running, which I don’t think it does right now.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Bridge between asyncio and Tornado
Tornado is designed to use a selector-based event loop. On Windows, where a proactor-based event loop has been the default since Python 3.8,...
Read more >Run tornado.testing.AsyncTestCase using asyncio event loop
I have an asyncio based class which I want to unit test. Using tornado.testing.AsyncTestCase this works quite well and easily. However, one ...
Read more >Developing with asyncio — Python 3.11.1 documentation
By default asyncio runs in production mode. In order to ease the development asyncio has a debug mode. There are several ways to...
Read more >Tornado - freshcode.club
Pattern is to start the event loop with `asyncio.run`. More detailed migration. ... A default `User-Agent` of `Tornado/ VERSION` is now used if...
Read more >IPython 7.0, Async REPL - Jupyter Blog
The default code will run in the existing asyncio/tornado loop that runs the kernel. Integration with Trio and Curio is still available, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It would be great if this was made easier.
I was able to at least find a simpler workaround:
Yes, see https://ipython.readthedocs.io/en/stable/whatsnew/version7.html#ipython-7-0-0
You can just await:
And it works.