subprocess.Popen execution of a script stuck
<p>I am trying to execute a command as follows but it is STUCK in <code>try</code> block as below until the timeout kicks in,the python script executes fine by itself independently,can anyone suggest why is it so and how to debug this?</p>

<pre><code>cmd = "python complete.py"
proc = subprocess.Popen(cmd.split(' '),stdout=subprocess.PIPE )
print "Executing %s"%cmd
try:
    print "In try" **//Stuck here**
    proc.wait(timeout=time_out)
except TimeoutExpired as e:
    print e
    proc.kill()
with proc.stdout as stdout:
    for line in stdout:
        print line,
</code></pre>

<p><code>proc.stdout</code> isn't available to be read <em>after the process exits</em>. Instead, you need to read it <em>while the process is running</em>. <code>communicate()</code> will do that for you, but since you're not using it, you get to do it yourself.</p>

<p>Right now, your process is almost certainly hanging trying to write to its stdout -- which it can't do, because the other end of the pipe isn't being read from.</p>

<p>See also <a href="http://stackoverflow.com/questions/1191374/using-module-subprocess-with-timeout">Using module 'subprocess' with timeout</a>.</p>

python