Skip to content

ProactorEventLoop.close(): set_wakeup_fd() only works in main thread #82744

Closed

Description

@carltongibson
BPO 38563
Nosy @vstinner, @asvetlov, @1st1, @miss-islington, @carltongibson, @felixxm
PRs
  • bpo-34679: ProactorEventLoop only uses set_wakeup_fd() in main thread #16901
  • [3.8] bpo-34679: ProactorEventLoop only uses set_wakeup_fd() in main thread (GH-16901) #16902
  • 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 2019-10-23.16:38:10.650>
    created_at = <Date 2019-10-23.12:13:28.326>
    labels = ['3.8', '3.9', 'type-crash', 'expert-asyncio']
    title = 'ProactorEventLoop.close(): set_wakeup_fd() only works in main thread'
    updated_at = <Date 2019-10-23.16:38:10.650>
    user = 'https://github.com/carltongibson'

    bugs.python.org fields:

    activity = <Date 2019-10-23.16:38:10.650>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-10-23.16:38:10.650>
    closer = 'vstinner'
    components = ['asyncio']
    creation = <Date 2019-10-23.12:13:28.326>
    creator = 'carltongibson'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 38563
    keywords = ['patch']
    message_count = 11.0
    messages = ['355214', '355216', '355217', '355220', '355222', '355224', '355225', '355231', '355234', '355235', '355240']
    nosy_count = 6.0
    nosy_names = ['vstinner', 'asvetlov', 'yselivanov', 'miss-islington', 'carltongibson', 'felixxm']
    pr_nums = ['16901', '16902']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue38563'
    versions = ['Python 3.8', 'Python 3.9']

    Activity

    1. carltongibson commented on Oct 23, 2019

      carltongibsonmannequin
      MannequinAuthor

      6ea29c5 for
      https://bugs.python.org/issue34687

      "Make asynico use ProactorEventLoop by default"

      This introducesd a regression in asgiref, and hence Django 3.0.x.

      django/asgiref#132
      https://code.djangoproject.com/ticket/30900

      The error from the asgiref issue is clearest:

      asgiref\sync.py:97: in __call__
          loop_future.result()
      ..\..\..\AppData\Local\Programs\Python\Python38\lib\concurrent\futures\_base.py:432: in result
          return self.__get_result()
      ..\..\..\AppData\Local\Programs\Python\Python38\lib\concurrent\futures\_base.py:388: in __get_result
          raise self._exception
      ..\..\..\AppData\Local\Programs\Python\Python38\lib\concurrent\futures\thread.py:57: in run
          result = self.fn(*self.args, **self.kwargs)
      asgiref\sync.py:130: in _run_event_loop
          loop.close()
      _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  
      
      self = <ProactorEventLoop running=False closed=False debug=False>
      
          def close(self):
              if self.is_running():
                  raise RuntimeError("Cannot close a running event loop")
              if self.is_closed():
                  return
          
      >       signal.set_wakeup_fd(-1)
      E       ValueError: set_wakeup_fd only works in main thread
      

      Off the main thread, we use a ThreadPoolExecutor and wait for the future to finish.

      It looks as if ProactorEventLoop needs to check the current thread before triggering the signal in close().

    2. carltongibson commented on Oct 23, 2019

      carltongibsonmannequin
      MannequinAuthor

      Reproduce steps, on Windows with Python 3.8.0, and a clean venv.

      git clone https://github.com/django/asgiref.git
      cd asgiref
      pip install -e .[tests]
      py.test .

    3. asvetlov commented on Oct 23, 2019

      @asvetlov
      Contributor

      Pull Request is welcome!

    4. changed the title [-]Asyncio regression on Windows with Python 3.8[/-] [+]ProactorEventLoop.close(): set_wakeup_fd() only works in main thread[/+] on Oct 23, 2019
    5. vstinner commented on Oct 23, 2019

      @vstinner
      Member

      That's basically the same issue than bpo-34679 but on close() rather than on creating the event loop.

    6. carltongibson commented on Oct 23, 2019

      carltongibsonmannequin
      MannequinAuthor

      Thanks for the speedy patch Victor. Great effort!

    7. vstinner commented on Oct 23, 2019

      @vstinner
      Member

      Thanks for the speedy patch Victor. Great effort!

      Can you try to manually test PR 16901?

    8. carltongibson commented on Oct 23, 2019

      carltongibsonmannequin
      MannequinAuthor

      OK, that seems fair :) Will do that tomorrow AM.

    9. vstinner commented on Oct 23, 2019

      @vstinner
      Member

      New changeset 1b53a24 by Victor Stinner in branch 'master':
      bpo-34679: ProactorEventLoop only uses set_wakeup_fd() in main thread (GH-16901)
      1b53a24

    10. miss-islington commented on Oct 23, 2019

      @miss-islington
      Contributor

      New changeset cbf474c by Miss Skeleton (bot) in branch '3.8':
      bpo-34679: ProactorEventLoop only uses set_wakeup_fd() in main thread (GH-16901)
      cbf474c

    11. vstinner commented on Oct 23, 2019

      @vstinner
      Member

      Yury and Andrew approved my PR 16901, so I merged it.

      Thanks for the bug report Carlton Gibson.

    12. carltongibson commented on Oct 23, 2019

      carltongibsonmannequin
      MannequinAuthor

      Super turn-around. Thank you all.

    13. 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

      Labels

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions