[issue41386] Popen.wait does not account for negative return codes
Eryk Sun
report at bugs.python.org
Fri Jul 24 20:46:58 EDT 2020
Eryk Sun <eryksun at gmail.com> added the comment:
In the Windows API, errors and exit status codes are all unsigned 32-bit integers. See SetLastError, GetLastError, ExitThread, ExitProcess, GetExitCodeThread, and GetExitCodeProcess. Even signed NTSTATUS and HRESULT values are commonly displayed as non-negative values, and, as exit status values, they're usually matched as unsigned integers.
I think, if anything, it should suffice to document the range of `Popen.returncode` in Windows as a 32-bit unsigned integer.
---
Even POSIX systems in many cases have no use for the signed exit status from C exit(). The POSIX wait() and waitpid() system calls only provide the lower byte (i.e. masked by 0xFF) of the exit status. The subprocess module takes advantage of this on POSIX systems in order to reserve negative return codes to indicate termination by a signal.
The newer waitid() system call should be able to return the signed 32-bit exit status. I think that's implemented on BSD and macOS, but waitid() in Linux 5.4 appears to only return the masked 8-bit status. For example:
>>> p = subprocess.Popen(['python', '-c', 'import os; os._exit(-1)'])
>>> os.waitid(os.P_PID, p.pid, os.WEXITED).si_status
255
----------
nosy: +eryksun
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41386>
_______________________________________
More information about the Python-bugs-list
mailing list