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: subprocess.call wrong exit code
Type: behavior Stage: resolved
Components: Windows Versions: Python 3.7
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: kayhayen, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2018-09-09 19:02 by kayhayen, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg324897 - (view) Author: Kay Hayen (kayhayen) Date: 2018-09-09 19:02
Hello there,

I am probably confusing myself. I am using this kind of code in Nuitka to emulate "os.execl" on Windows, and so far it never let me down:

            r = subprocess.call(
                args,
                shell = False
            )

            print (r, args)

            sys.exit(r)

When i execute my tests with Nuitka and Python 3.6 and everything before, this gives:

1 ['test_call.exe']
1 ['C:\\Python36_32\\python.exe', '-S', '..\\..\\nuitka\\__main__.py', '--run', 'test/test_call.py']

And with python 3.7 it gives:

0 ['test_call.exe']
0 ['C:\\Python37_32\\python.exe', '-S', '..\\..\\nuitka\\__main__.py', '--run', 'test/test_call.py']

So I am in Nuitka re-executing itself without the site module, and then immediately the created binary. For 3.7 it doesn't give me an error. I manually confirmed that "test_call.exe" indeed gives error code 1 as well, in both bash and cmd.exe, but it is not seen in the return value. Checking existing issues, I didn't find any hint at all, how this can be. I added "shell = False" to make it clear that no "cmd.exe" should be used, for which there had been issues.

I also confirmed, by adding a exit(27), that if I simulate that "test_call.exe" gave 27, rather then 0, then that one is detected by the exec, so what could be going on here. But I am also sure I don't confuse binaries or so, plus it's working as expected in other Python versions than 3.7.0 here.

This happens with 64 bits too, I am only citing 32 bits. And it is happening with just about every compiled unit test that gives an error exit, where otherwise e.g. tests that check for error exits to be the case work nicely.

Thanks for any help or direction you can give me there. I am at loss.

Yours,
Kay
msg324899 - (view) Author: Kay Hayen (kayhayen) Date: 2018-09-09 19:10
I think that the whole reason I was doing this, is because with "os.execl" on Windows, the exit code was always lost, but of course it is very important and "subprocess.call" promises to return it. 

I just tried if 3.7 has any better exit code handling right there for "os.execl", but apparently it's not the case.
msg324994 - (view) Author: Kay Hayen (kayhayen) Date: 2018-09-11 06:23
So I was confused indeed. 

Actually I am observing in other tests at least, that apparently Nuitka compiled execution in my tests can import _testcapi module, which normal execution of the test does not manage. 

Then there is the possibility that the exit code is indeed "0" and different.

The failure to import that module is old, and something I consider to raise as a separate issue. Closing this one as it's not worthy.
History
Date User Action Args
2022-04-11 14:59:05adminsetgithub: 78796
2018-09-11 06:23:49kayhayensetstatus: open -> closed

messages: + msg324994
stage: resolved
2018-09-09 19:10:45kayhayensetmessages: + msg324899
2018-09-09 19:02:37kayhayencreate