Skip to content

ProactorEventLoop ignores Ctrl+C after closing unrelated loop #91170

Closed

Description

@mhils
mannequin
BPO 47014
Nosy @asvetlov, @1st1, @mhils
Files
  • proactor-repro.py
  • 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 2022-03-23.21:49:14.208>
    created_at = <Date 2022-03-14.17:14:47.999>
    labels = ['type-bug', '3.10', 'expert-asyncio']
    title = 'ProactorEventLoop ignores Ctrl+C after closing unrelated loop'
    updated_at = <Date 2022-03-23.21:49:14.207>
    user = 'https://github.com/mhils'

    bugs.python.org fields:

    activity = <Date 2022-03-23.21:49:14.207>
    actor = 'asvetlov'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-03-23.21:49:14.208>
    closer = 'asvetlov'
    components = ['asyncio']
    creation = <Date 2022-03-14.17:14:47.999>
    creator = 'mhils'
    dependencies = []
    files = ['50675']
    hgrepos = []
    issue_num = 47014
    keywords = []
    message_count = 2.0
    messages = ['415169', '415200']
    nosy_count = 3.0
    nosy_names = ['asvetlov', 'yselivanov', 'mhils']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue47014'
    versions = ['Python 3.10']

    Activity

    1. mhils commented on Mar 14, 2022

      mhilsmannequin
      MannequinAuthor

      When a (second) ProactorEventLoop is garbage-collected, the current ProactorEventLoop starts to ignore Ctrl+C on Windows until it is woken up. The attached repro shows a minimal example. Uncommenting the create_task call or not using a second event loop fixes the behavior.

      I couldn't find any shared/global objects in asyncio/windows_events.py, so I'm not sure what is causing this, or why the wakeup task helps.

      FWIW, the second event loop in our code base originated from a stray get_event_loop() call, one more example that speaks in favor of get_running_loop()!

    2. asvetlov commented on Mar 14, 2022

      @asvetlov
      Contributor

      Ctrl-C handling is added by bpo-23057

      It uses signal.set_wakeup_fd() https://github.com/asvetlov/cpython/blob/main/Lib/asyncio/proactor_events.py#L631-L634

      So, the last event loop steals Ctrl+C handling.
      Not sure if we can improve it.
      Running two concurrent loops in the same thread is a bad idea for many reasons. Ctrl+C is not the only reason.

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