Skip to content

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

Closed

Description

@vstinner
BPO 33792
Nosy @vstinner, @asvetlov, @1st1, @miss-islington
PRs
  • bpo-33792: Add selector and proactor windows policies #7487
  • [3.7] bpo-33792: Add selector and proactor windows policies (GH-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']

    Activity

    1. vstinner commented on Jun 7, 2018

      @vstinner
      MemberAuthor

      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.

    2. vstinner commented on Jun 7, 2018

      @vstinner
      MemberAuthor

      Ugly workaround:

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

      It uses a private attribute :-(

    3. asvetlov commented on Jun 7, 2018

      @asvetlov
      Contributor

      Looks like we need a proactor policy class.

    4. 1st1 commented on Jun 8, 2018

      @1st1
      Member

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

    5. miss-islington commented on Jun 8, 2018

      @miss-islington
      Contributor

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

    6. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions