Add an option to run an asyncio event loop automatically
See original GitHub issueExperimenting with asyncio
righ now is a pain. If I want just to use aiohttp
to make a get request, I need to do:
import asyncio
import aiohttp
async def main():
content = await asyncio.get('http://foo.com').content
print(content)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Compare to doing the same with requests
:
import requets
print(requests.get('http://foo.com').content)
I wish ptpython would have an --asyncio
option which starts an event loop with the shell and run any command in it.
So my example with aiohttp
would become:
$ ptpython --asyncio
Then:
import aiohttp
print(await asyncio.get('http://foo.com').content)
Issue Analytics
- State:
- Created 8 years ago
- Reactions:4
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Add an option to run an asyncio event loop automatically #9166
I've whipped together a quick extension that adds an %%asyncio cell magic. You can use it like this: In [1]: %load_ext asyncio_magic In...
Read more >Event Loop — Python 3.11.1 documentation
The event loop is the core of every asyncio application. Event loops run asynchronous tasks and callbacks, perform network IO operations, and run...
Read more >asyncio create_task to run forever - python - Stack Overflow
1 Answer 1 · loop.run_until_complete(some_func()) - what you already used; run the event loop until the some_func coroutine finishes. · loop.
Read more >Asyncio Event Loops Tutorial - TutorialEdge.net
In this tutorial we look at the various ways you can define and work with event loops in Asyncio.
Read more >How to Create Asyncio Tasks in Python
A task is executed independently. This means it is scheduled in the asyncio event loop and will execute regardless of what else happens...
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
I talked with an iPython dev, he provided me with a %magic_command which open a bloc that does just that. Since ptpython doesn’t have this concept, wrapping could work, but then you need to give it access to the variable of the previous scope, which mean you need to copy local(), pass it to the functions, and merge it to the new locals() dict.
wait. does https://bugs.python.org/issue37028 mean we can use top level await in ptpython with python 3.8 without any change?