Python Subprocess.Popen not getting exit, it getting hanged

1.1k views Asked by At

I'm using subprocess.Popen to invoke the console application. The console application itself calling another child process to perform download operation. The parent process exits once its invoke the child process.

I'm able to get the output of the child process while running the script manually in command prompt.

But the subprocess.Popen getting hanged while running the script in system environment( post commit hook). The subprocess not getting exit.

 p1 = subprocess.Popen([Application,arg1, arg2, arg3], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
 Down_out = p1[0]
 Down_Err = p1[1]

Thanks in advance

1

There are 1 answers

1
johannestaas On

It's hard to say from the info you gave, but it may be that arguments is a string with multiple arguments when they should be split into multiple elements in the list. The behavior of the program you are executing will not be what you expect if you combine all arguments into one string.

eg:

>>> from subprocess import Popen
>>> Popen(['touch', '/tmp/testing /tmp/foo']).communicate()
touch: cannot touch ‘/tmp/testing /tmp/foo’: No such file or directory
(None, None)
>>> Popen(['touch', '/tmp/testing', '/tmp/foo']).communicate()
(None, None)

In the first one, '/tmp/testing /tmp/foo' is one string.

In the second, it's two separate elements in the list. That ran as expected.

I am guessing that yours is hanging because of invalid arguments.