Issues with subprocess in Linux (Travis)
Closed this issue · 8 comments
In an effort to make a dtm test (in mooray as it uses pytest...) a problem with subprocess in Travis is seen. The following code works fine locally (Windows):
def test_homepage_ping(execute_task):
response = execute_task(command='ping www.sevanssp.com', path=getcwd(), shell=True, pipe=True)
assert response['returncode'] == 0, print(response)
assert 'ping' in response['output'].lower(), print(response)
assert '194.63.249.212' in response['output'], print(response)
This does not work in Travis. Further investigation shows that shell=True
freezes the testing completely. timeout=120
has no effect. Without shell=True
the command doesn't work in Linux.
shell=True on Linux
There are differences on Windows and Linux OS whether commands like ping
and others can be executed directly or needs to passed through a shell. That's just how it is.
Stalling build
That is strange. Did you manage to capture the piped stdout
? I hope that will give a clue to what is going on.
No, the stall gives no feedback. Travis stops it when it has been idle for 10 minutes. shell=False
gives FileNotFoundError
, as expected.
I suggest you rewrite the test to unittest format in dtm
, so we can investigate (and so we can learn how this test looks in unittest format)
Sure, I'll do that.
Have you tried another command like ls
?
I've only tested ping www.sevanssp.com
. But I've detached subprocess
from execute_task
and gotten the same result. so the error is not in execute_task
Hmmm. Can it be that some commands like ping
are not allowed or that requesting www.
redirects to https:\ and that for some reason this causes a stall?
try ping https:\\sevanssp.com
'ping -c 4 www.sevanssp.com' works in linux
It would be good to understand why it is not possible to send this command as a list or tuple, though...
Basically you should pass a sequence (list/tuple) with shell=False and a string with shell=True. It’s because of how Python creates the new processes and send them information, which differs on Windows and Linux.
On Windows you can pass either a string or a sequence since Python interprets the sequence of arguments into a string anyway with shell=False. With shell=True the string is sent directly to the shell.
The same thing happens on Linux with shell=True. However, if a sequence is passed, it is sent as positional arguments to the shell not to the command (first item in the sequence).
Issue logged as #5