-
-
Notifications
You must be signed in to change notification settings - Fork 348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide an API that does WaitForSingleObject on Windows #233
Comments
Looks like Windows already implements an asynchronous signaling mechanism around |
Yeah, there are lots of options for how to tackle this. In fact Windows actually has two different thread pool APIs that both have special support for delegating Some considerations: With the Windows thread pool APIs, I'm having a lot of trouble figuring out what exactly happens when you cancel a wait. Ideally, you call With the Windows thread pool APIs, or with And in general, with the Windows thread pool APIs, we have very little visibility or insight into what they're doing. Maybe it's great, but if someone does have a problem it might be impossible to debug or fix. Our thread APIs are probably not the best possible (e.g. I'm sure the Windows ones are faster), but having 1 thread pool seems simpler than having 2, and if ours runs into problems we can fix them. So that's why I've been leaning towards using |
This was fixed in #575 |
This appears to have a race condition. The new thread might start waiting only after the handle has been closed. This could be fixed by making the thread close the |
As noted in #52, there are some events on Windows that can only be detected by calling one of the
WaitFor
family of functions (WaitForSingleObject
,WaitForSingleObjectEx
,WaitForMultipleObjects
, etc. etc.). Some examples include child process exit (required for #4), and detecting console input (required for #174).To resolve this issue, we should provide a
trio.hazmat.WaitForSingleObject
function that takes aHANDLE
, and waits for it, and is cancellable.The most straightforward way to do this is to allocate a thread to sit in
WaitForSingleObjectEx
, which can do an "alertable wait", which means that it's possible to cause the function to wake up early by callingQueueUserAPC
. So we would useQueueUserAPC
from inside our abort callback to implement cancellation. There are some more notes in_io_windows.py
.The text was updated successfully, but these errors were encountered: