Message156470
The documentation for sys.exit says, "The optional argument arg can be an integer giving the exit status (defaulting to zero), or another type of object".
However, the arguments that are treated as exit statuses are actually "subtypes of int".
So, a bool argument is fine:
$ python2.7 -c "import sys; sys.exit(False)"; echo $?
0
But a long argument is not:
$ python2.7 -c "import sys; sys.exit(long(0))"; echo $?
0
1
The latter behaviour can be surprising since functions like os.spawnv may return the exit status of the executed process as a long on some platforms, so that if you try to pass on the exit code via
code = os.spawnv(...)
sys.exit(code)
you may get a mysterious surprise: code is 0 but exit code is 1.
It would be simple to change line 1112 of pythonrun.c from
if (PyInt_Check(value))
to
if (PyInt_Check(value) || PyLong_Check(value))
(This issue is not present in Python 3 because there is no longer a distinction between int and long.) |
|
Date |
User |
Action |
Args |
2012-03-21 00:08:00 | gdr@garethrees.org | set | recipients:
+ gdr@garethrees.org |
2012-03-21 00:08:00 | gdr@garethrees.org | set | messageid: <1332288480.19.0.200013792885.issue14376@psf.upfronthosting.co.za> |
2012-03-21 00:07:59 | gdr@garethrees.org | link | issue14376 messages |
2012-03-21 00:07:59 | gdr@garethrees.org | create | |
|