I wrote this python script (part of a bigger program) to launch a php script and wait for the output.

The PHP script takes almost 15 minutes to run, as it is spawning several perl & C programs of its own.

When I launch the php script by itself, it runs perfectly and always has.

But when I wrap this in python, it runs for a while, then just stops.
When I view active tasks in my shell, I can still see the python script running and the php script it allegedly is running still shows up. However, it never completes, it just hangs there. The PHP script should be writing to a file, but after about 5 minutes it just stops doing anything.

def protocol2():
	cmd = 'php /usr/bin/protocol2 -q 1 -s %s -t %s -o %s -m %i > /dev/null' %(sys.argv[1]+'.faa',sys.argv[2]+'.faa','./',defaults['max_gsat'])
	args = shlex.split(cmd)
	return subprocess.Popen(args, stdout=subprocess.PIPE)
P2 = protocol2()
P2.wait()
print "Finished"

From the docs http://docs.python.org/library/subprocess.html

Popen.wait()

Wait for child process to terminate. Set and return returncode attribute.

Warning

This will deadlock when using stdout=PIPE and/or stderr=PIPE and the child process generates enough output to a pipe such that it blocks waiting for the OS pipe buffer to accept more data. Use communicate() to avoid that.

Thanks! I removed "stdout=subprocess.PIPE" and now it runs to completion. Although it spits a lot of stuff out into my shell.

How can I run my python script and suppress Popen's output buffer?

Thanks!

stdout= '/dev/null' ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.