This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients gvanrossum, sbt, steve.dower, tim.golden, vstinner, yselivanov, zach.ware
Date 2015-01-21.16:35:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1421858139.24.0.728719194771.issue23095@psf.upfronthosting.co.za>
In-reply-to
Content
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().
History
Date User Action Args
2015-01-21 16:35:39vstinnersetrecipients: + vstinner, gvanrossum, tim.golden, sbt, zach.ware, yselivanov, steve.dower
2015-01-21 16:35:39vstinnersetmessageid: <1421858139.24.0.728719194771.issue23095@psf.upfronthosting.co.za>
2015-01-21 16:35:39vstinnerlinkissue23095 messages
2015-01-21 16:35:39vstinnercreate