Skip to content

Commit cc786b7

Browse files
committed
Use WaitForSingleObject() instead of trusting TimerOrWaitFired.
1 parent 9a45889 commit cc786b7

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

asyncio/windows_events.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,14 +327,21 @@ def wait_for_handle(self, handle, timeout=None):
327327
handle, self._iocp, ov.address, ms)
328328
f = _WaitHandleFuture(wh, loop=self._loop)
329329

330-
def finish(timed_out, _, ov):
330+
def finish(trans, key, ov):
331331
if not f.cancelled():
332332
try:
333333
_overlapped.UnregisterWait(wh)
334334
except OSError as e:
335335
if e.winerror != _overlapped.ERROR_IO_PENDING:
336336
raise
337-
return not timed_out
337+
# Note that this second wait means that we should only use
338+
# this with handles types where a successful wait has no
339+
# effect. So events or processes are all right, but locks
340+
# or semaphores are not. Also note if the handle is
341+
# signalled and then quickly reset, then we may return
342+
# False even though we have not timed out.
343+
return (_winapi.WaitForSingleObject(handle, 0) ==
344+
_winapi.WAIT_OBJECT_0)
338345

339346
self._cache[ov.address] = (f, ov, None, finish)
340347
return f

0 commit comments

Comments
 (0)