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.

classification
Title: Use _winapi.WaitForMultipleObjects in Popen.wait()
Type: enhancement Stage: resolved
Components: Library (Lib), Windows Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: eryksun, paul.moore, steve.dower, tim.golden, vstinner, zach.ware
Priority: normal Keywords: patch

Created on 2016-09-15 10:42 by eryksun, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue_28168_03.patch eryksun, 2016-09-16 23:47 review
issue_28168_04.patch eryksun, 2016-09-17 00:13 review
Messages (6)
msg276544 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2016-09-15 10:42
On Unix, waiting on an instance of subprocess.Popen in the main thread is interruptible by Ctrl+C. On Windows, it currently calls _winapi.WaitForSingleObject, which isn't interruptible. It should instead call _winapi.WaitForMultipleObjects, which automatically adds the SIGINT event object from _PyOS_SigintEvent() when called from the main thread.
msg276546 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2016-09-15 10:47
This patch makes the trivial change to the Popen.wait() method and also modifies _winapi.WaitForMultipleObjects to restart the wait if SIGINT is ignored or the handler didn't raise an exception.
msg276760 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2016-09-17 00:13
Hopefully this is my last change until someone reviews this. I decided to make it an error to pass an empty sequence, which previously would implicitly wait on the SIGINT event. This way simplifies the code and prevents someone from accidentally waiting forever on SIGINT when it's ignored or doesn't raise an exception. There should always be at least 1 other handle in the wait list.
msg276763 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-09-17 02:36
Oh nice, you implemented the PEP 475 for _winapi.WaitForMultipleObjects()! I missed this function when implementing this PEP :-)
msg276764 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-09-17 02:37
> I decided to make it an error to pass an empty sequence

It makes sense since the original WaitForMultipleObjects() also requires at least one object:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms687025(v=vs.85).aspx

nCount [in]

    The number of object handles in the array pointed to by lpHandles. The maximum number of object handles is MAXIMUM_WAIT_OBJECTS. This parameter cannot be zero.
msg389140 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2021-03-20 02:32
I'm no longer interested in solving the SIGINT event problem locally at the wait site. A common implementation of _Py_Sleep, _Py_WaitForSingleObject, and _Py_WaitForMultipleObjects is needed. _winapi.WaitForSingleObject would call _Py_WaitForSingleObject and automatically support the SIGINT event on the main thread.
History
Date User Action Args
2022-04-11 14:58:36adminsetgithub: 72355
2021-03-20 02:32:58eryksunsetstatus: open -> closed
resolution: rejected
messages: + msg389140

stage: patch review -> resolved
2016-09-17 02:37:48vstinnersetmessages: + msg276764
2016-09-17 02:36:11vstinnersetnosy: + vstinner
messages: + msg276763
2016-09-17 00:13:00eryksunsetfiles: + issue_28168_04.patch

messages: + msg276760
2016-09-16 23:47:27eryksunsetfiles: + issue_28168_03.patch
2016-09-16 23:46:48eryksunsetfiles: - issue_28168_02.patch
2016-09-16 23:46:41eryksunsetfiles: - issue_28168_01.patch
2016-09-15 11:41:02eryksunsetfiles: + issue_28168_02.patch
2016-09-15 10:47:44eryksunsetfiles: + issue_28168_01.patch
keywords: + patch
messages: + msg276546

stage: needs patch -> patch review
2016-09-15 10:42:49eryksuncreate