Eryk Sun <eryk...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue41386>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to