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

asyncio: how to set a "Proactor event loop" policy? Issue with asyncio.run() #77973

Closed
vstinner opened this issue Jun 7, 2018 · 5 comments
Closed

Comments

@vstinner
Copy link
Member

@vstinner vstinner commented Jun 7, 2018

BPO 33792
Nosy @vstinner, @asvetlov, @1st1, @miss-islington
PRs
  • #7487
  • #7508
  • 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 = None
    closed_at = <Date 2018-06-08.03:43:15.087>
    created_at = <Date 2018-06-07.10:02:04.335>
    labels = ['3.7', '3.8', 'expert-asyncio']
    title = 'asyncio: how to set a "Proactor event loop" policy? Issue with asyncio.run()'
    updated_at = <Date 2018-06-08.03:43:15.086>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2018-06-08.03:43:15.086>
    actor = 'yselivanov'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-06-08.03:43:15.087>
    closer = 'yselivanov'
    components = ['asyncio']
    creation = <Date 2018-06-07.10:02:04.335>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 33792
    keywords = ['patch']
    message_count = 5.0
    messages = ['318919', '318924', '318929', '319002', '319004']
    nosy_count = 4.0
    nosy_names = ['vstinner', 'asvetlov', 'yselivanov', 'miss-islington']
    pr_nums = ['7487', '7508']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue33792'
    versions = ['Python 3.7', 'Python 3.8']

    @vstinner
    Copy link
    Member Author

    @vstinner vstinner commented Jun 7, 2018

    asyncio documentation suggets to use:
    ---

    import asyncio, sys
    
    if sys.platform == 'win32':
        loop = asyncio.ProactorEventLoop()
        asyncio.set_event_loop(loop)

    https://docs.python.org/dev/library/asyncio-eventloops.html

    But this code doesn't work with asyncio.run() which creates a new event loop with the current policy, and the default policy on Windows is to use SelectorEventLoop.

    I cannot find a "Proactor event loop policy" in asyncio, nor how to change the default policy to use Proactor event loop.

    The workaround is to not use asyncio.run() which has been added in Python 3.7.

    @vstinner
    Copy link
    Member Author

    @vstinner vstinner commented Jun 7, 2018

    Ugly workaround:

    policy = asyncio.get_event_loop_policy()
    policy._loop_factory = asyncio.ProactorEventLoop

    It uses a private attribute :-(

    @asvetlov
    Copy link
    Contributor

    @asvetlov asvetlov commented Jun 7, 2018

    Looks like we need a proactor policy class.

    @1st1
    Copy link
    Member

    @1st1 1st1 commented Jun 8, 2018

    New changeset 8f40429 by Yury Selivanov in branch 'master':
    bpo-33792: Add selector and proactor windows policies (GH-7487)
    8f40429

    @miss-islington
    Copy link
    Contributor

    @miss-islington miss-islington commented Jun 8, 2018

    New changeset 0738443 by Miss Islington (bot) in branch '3.7':
    bpo-33792: Add selector and proactor windows policies (GH-7487)
    0738443

    @1st1 1st1 closed this Jun 8, 2018
    @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
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants