python / python/cpython

Potential Windows-specific lost event race in the implementation of time.sleep

Open
#135,407 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

extension-modules OS-windows type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug description:

In the Windows-specific implementation of time.sleep there appears this code:

https://github.com/python/cpython/blob/b706ff003c536c5bca24dfdd3a8917bffcfa3df1/Modules/timemodule.c#L2341-L2345

If a control-C event happens after PyErr_CheckSignals returns, but before ResetEvent is called, I believe that event may be lost.

This is probably a hard race window to hit, and I don't have a Windows development environment, so I have not confirmed that it is possible.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Windows-specific time.sleep implementation in Modules/timemodule.c at the linked lines, then examine the ordering of PyErr_CheckSignals and ResetEvent. Investigate whether a control-C event can occur in that window on Windows; done means confirming or disproving the lost-event race and documenting or correcting the behavior with coverage if applicable.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.