GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Race with KeyboardInterrupt in asyncio loop run_forever() method · Issue #94732 · python/cpython

Race with KeyboardInterrupt in asyncio loop run_forever() method #94732

New issue
Copy link
New issue
Copy link
Closed
Closed
Race with KeyboardInterrupt in asyncio loop run_forever() method#94732
Copy link
Labels
topic-asynciotype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@hetmankp
hetmankp
opened on Jul 11, 2022
Issue body actions

There is a race with the KeyboardInterrupt exception in the asyncio.base_events.BaseEventLoop.run_forever() method. While an attempt is made to restore the environment to its previous state before run_forever() completes with a try...finally, a couple items find themselves outside the try...finally. Specifically, a badly timed KeyboardInterrupt will mean that, neither the self._thread_id value or the hooks set by sys.set_asyncgen_hooks() will be correctly restored. Both of these should be moved inside the try...finally.

cpython/Lib/asyncio/base_events.py

Lines 596 to 600 in c9118af

self._thread_id = threading.get_ident()
old_agen_hooks = sys.get_asyncgen_hooks()
sys.set_asyncgen_hooks(firstiter=self._asyncgen_firstiter_hook,
finalizer=self._asyncgen_finalizer_hook)

This applies to all existing version of Python on all platforms.

Activity

  1. hetmankp
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Jul 11, 2022
  2. kumaraditya303
    added
    topic-asyncio
    on Sep 4, 2022
  3. ezio-melotti
    added this to asyncioon Sep 4, 2022
  4. ezio-melotti
    moved this to Todo in asyncioon Sep 4, 2022
  5. gvanrossum
    added a commit that references this issue on Sep 14, 2022

    Merge branch 'main' into pythongh-94732

    c95d0ff
  6. hetmankp
    added a commit that references this issue on Oct 3, 2022

    pythongh-94732: Fix KeyboardInterrupt race in asyncio run_forever()

    adc04fb
  7. gvanrossum
    added a commit that references this issue on Oct 3, 2022

    gh-94732: Fix KeyboardInterrupt race in asyncio run_forever() (#97765)

    3a49dbb
  8. miss-islington
    added 4 commits that reference this issue on Oct 3, 2022

    pythongh-94732: Fix KeyboardInterrupt race in asyncio run_forever() (p…

    0d7548e

    pythongh-94732: Fix KeyboardInterrupt race in asyncio run_forever() (p…

    e4b30d9

    gh-94732: Fix KeyboardInterrupt race in asyncio run_forever() (GH-97765)

    4420da0

    gh-94732: Fix KeyboardInterrupt race in asyncio run_forever() (GH-97765)

    a7e2811
  9. gvanrossum commented on Oct 3, 2022

    @gvanrossum
    gvanrossum
    on Oct 3, 2022
    Member
    More actions

    Fixed!

    @hetmankp: Thanks for being flexible regarding the CLA bot. I hope the problem is now fixed for you going forward?

  10. gvanrossum
    closed this as completedon Oct 3, 2022
  11. Repository owner moved this from Todo to Done in asyncioon Oct 3, 2022
  12. carljm
    added a commit that references this issue on Oct 3, 2022

    Merge branch 'main' into dictwatch

    e83abac
  13. hetmankp commented on Oct 4, 2022

    @hetmankp
    hetmankp
    on Oct 4, 2022
    ContributorAuthor
    More actions

    Fixed!

    @hetmankp: Thanks for being flexible regarding the CLA bot. I hope the problem is now fixed for you going forward?

    Thanks @gvanrossum , yes as far as CPython is concerned I should be covered (not sure why the simpler email format wasn't working but I guess it will remain a mystery for now).

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

    topic-asynciotype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    • asyncio
      Status
      Done
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.