Skip to content

Add an option to run an asyncio event loop automatically #99

Open
@sametmax

Description

@sametmax

Experimenting 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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions