STINNER Victor added the comment:

To wait for the exit of the subprocess, we use RegisterWaitForSingleObject(). 
To cancel this wait, we can use UnregisterWait() which returns immediatly. 
Problem: UnregisterWait() doesn't tell us if the wait was cancelled or not, the 
cancellation is asynchronous. Second problem: the wait may have been signaled 
to the IOCP... or not. The wait may be signaled after the call to 
UnregisterWait(), since the cancellation is asynchronous (I'm not sure of that, 
but it doesn't change everything). This can be explained by the implementation: 
RegisterWaitForSingleObject() is implemented with a pool of threads.

Windows XP introduced UnregiterWaitEx() which can be used to be notified when 
the wait has been cancelled. Cool. But the notification requires an Event 
object. And how can we asynchronously wait for this Event? Using 
RegisterWaitForSingleObject()! Wait, what? We were cancelling another 
RegisterWaitForSingleObject().

To be fully asynchronous (no performance impact), cancelling a 
RegisterWaitForSingleObject() wait requires a new Event object and call 
RegisterWaitForSingleObject() on it.

--

In Python, we must ensure that the Overlapped object used by 
RegisterWaitForSingleObject() is kept alive until the wait is signalled, or 
until we are sure that the wait was cancelled. Otherwise, the program may crash.

To keep the Overlapped object alive, we keep indirectly in a _WaitHandleFuture 
object, and this future is registered in IocpProactor._cache.

I'm working on a change to use UnregiterWaitEx().

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue23095>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to