Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement asyncio.run() #76495

Closed
1st1 opened this issue Dec 13, 2017 · 7 comments
Closed

Implement asyncio.run() #76495

1st1 opened this issue Dec 13, 2017 · 7 comments
Assignees
Labels
3.7 expert-asyncio type-feature

Comments

@1st1
Copy link
Member

@1st1 1st1 commented Dec 13, 2017

BPO 32314
Nosy @vstinner, @asvetlov, @ambv, @1st1
PRs
  • #4852
  • #5262
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/1st1'
    closed_at = <Date 2017-12-14.14:43:04.914>
    created_at = <Date 2017-12-13.21:47:08.564>
    labels = ['type-feature', '3.7', 'expert-asyncio']
    title = 'Implement asyncio.run()'
    updated_at = <Date 2018-01-21.19:57:01.702>
    user = 'https://github.com/1st1'

    bugs.python.org fields:

    activity = <Date 2018-01-21.19:57:01.702>
    actor = 'yselivanov'
    assignee = 'yselivanov'
    closed = True
    closed_date = <Date 2017-12-14.14:43:04.914>
    closer = 'yselivanov'
    components = ['asyncio']
    creation = <Date 2017-12-13.21:47:08.564>
    creator = 'yselivanov'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32314
    keywords = ['patch']
    message_count = 7.0
    messages = ['308256', '308258', '308259', '308301', '308303', '308308', '310381']
    nosy_count = 4.0
    nosy_names = ['vstinner', 'asvetlov', 'lukasz.langa', 'yselivanov']
    pr_nums = ['4852', '5262']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue32314'
    versions = ['Python 3.7']

    @1st1
    Copy link
    Member Author

    @1st1 1st1 commented Dec 13, 2017

    There's a fairly extensive discussion here: python/asyncio#465

    In short, asyncio.run() is a pretty straightforward addition, so let's add it.

    The discussion was more focused on the asyncio.run_forever() proposal. I now think that it shouldn't be implemented in asyncio. Instead we should fix cases where 'loop.run_forever' is usually required. Mainly that's servers, and they are easily fixable by making "Server" an async context manager and implementing a "server.serve_forever()" method. That way, with asyncio.run():

        async def serve_something():
           async with asyncio.start_server(...) as server:
               await server.serve_forever()
    
        asyncio.run(serve_something())  # No loop.run_forever()!

    @1st1 1st1 added the 3.7 label Dec 13, 2017
    @1st1 1st1 self-assigned this Dec 13, 2017
    @1st1 1st1 added expert-asyncio type-feature labels Dec 13, 2017
    @asvetlov
    Copy link
    Contributor

    @asvetlov asvetlov commented Dec 13, 2017

    I like avoiding run_forever() -- the function always was too cumbersome.

    @1st1
    Copy link
    Member Author

    @1st1 1st1 commented Dec 13, 2017

    I'll open a separate issue to improve Server's API. AFAIK it's the main reason for having run_forever().

    @1st1
    Copy link
    Member Author

    @1st1 1st1 commented Dec 14, 2017

    New changeset 02a0a19 by Yury Selivanov in branch 'master':
    bpo-32314: Implement asyncio.run() (bpo-4852)
    02a0a19

    @1st1 1st1 closed this Dec 14, 2017
    @vstinner
    Copy link
    Member

    @vstinner vstinner commented Dec 14, 2017

    Wow, I really love your new function. Thanks Yury! asyncio examples in the doc look much better now!

    @1st1
    Copy link
    Member Author

    @1st1 1st1 commented Dec 14, 2017

    Wow, I really love your new function. Thanks Yury! asyncio examples in the doc look much better now!

    This year I'll stay for the sprints at PyCon, and will focus on improving the docs further. I needed asyncio.run for that :)

    @1st1
    Copy link
    Member Author

    @1st1 1st1 commented Jan 21, 2018

    New changeset a4afcdf by Yury Selivanov in branch 'master':
    bpo-32314: Fix asyncio.run() to cancel runinng tasks on shutdown (bpo-5262)
    a4afcdf

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 expert-asyncio type-feature
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants