[issue24045] Behavior of large returncodes (sys.exit(nn))

Eryk Sun report at bugs.python.org
Fri Feb 26 14:37:05 EST 2021


Eryk Sun <eryksun at gmail.com> added the comment:

It's still the case in 3.10 that unsigned status codes are limited to 0x7FFF_FFFF, and any larger value gets mapped to -1 (0xFFFF_FFFF). For example:

    >>> rc = subprocess.call([sys.executable, '-c', 'raise SystemExit(0x7FFF_FFFF)'])
    >>> hex(rc)
    '0x7fffffff'
    >>> rc = subprocess.call([sys.executable, '-c', 'raise SystemExit(0x8000_0000)'])
    >>> hex(rc)
    '0xffffffff'
    >>> rc = subprocess.call([sys.executable, '-c', 'raise SystemExit(0xC000_0005)'])
    >>> hex(rc)
    '0xffffffff'

WinAPI ExitProcess() and GetExitCodeProcess() use unsigned values. The latter is called by subprocess.Popen.wait(). In practice, this return code, which may be larger than 0x7FFF_FFFF, might get passed to SystemExit() or os._exit().

----------
type:  -> behavior
versions: +Python 3.10, Python 3.8, Python 3.9 -Python 2.7, Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue24045>
_______________________________________


More information about the Python-bugs-list mailing list