1

I am trying to execute a command as follows but it is STUCK in try 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?

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,
asked Oct 7, 2016 at 0:56
3
  • Depends on the details of the command, but the most likely problem is that it's sitting around trying to write to its stdout (but can't, because you're not reading from the other end of the pipeline). Commented Oct 7, 2016 at 1:06
  • 1
    This is why the docs clearly recommend you to use .communicate(), especially if you have redirected stdout or stderr. Commented Oct 7, 2016 at 1:08
  • @Owen, I don't agree that this is a dupe of that particular question -- they're not calling stdout.read() here. If they were, they wouldn't have this bug. (Now, if they were redirecting stderr to a separate FIFO but only reading from stdout, then they'd be back in that position, but that's not the case at hand). Commented Oct 7, 2016 at 1:10

1 Answer 1

1

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

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.

See also Using module 'subprocess' with timeout.

answered Oct 7, 2016 at 1:06
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.