[issue40913] time.sleep ignores errors on Windows

Eryk Sun report at bugs.python.org
Fri Jun 12 15:50:09 EDT 2020


Eryk Sun <eryksun at gmail.com> added the comment:

If WaitForSingleObjectEx fails, do you think the system error code should be raised as an OSError? Probably an invalid-handle or access-denied error is too cryptic here. It may be better to raise something like RuntimeError('time.sleep(): invalid SIGINT event handle'). 

> You could test this by getting the event and CloseHandle-ing it. 

Yes, that's a simpler approach. It should work in a child process that's well controlled. 

I was thinking of a less controlled environment, in which there's a chance that another waitable object will reuse the handle, such as a file object. The test would be reliable regardless of process context (but only in the main thread, of course) if there were a _PyOS_SetSigintEvent function -- or if sigint_event were directly accessible in _testcapimodule. It could just temporarily set a duplicate handle with no access. For example:

    >>> h1 = CreateEvent(None, True, True, None)
    >>> WaitForSingleObject(h1, 0)
    0
    >>> hp = GetCurrentProcess()
    >>> h2 = DuplicateHandle(hp, h1, hp, 0, False, 0)
    >>> WaitForSingleObject(h2, 0)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    pywintypes.error: (5, 'WaitForSingleObject', 'Access is denied.')

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40913>
_______________________________________


More information about the Python-bugs-list mailing list