0

The following little script is supposed to run a shell command with a parameter every 10 minutes. It's ran correctly once (30 minutes ago) however isn't playing ball now (should have done the process another 2 times since). Have I made an error?

while(True):
  subprocess.call(["command","param"])
  time.sleep(600)
2
  • is the process still running? Commented Apr 26, 2012 at 16:29
  • What kind of command are you calling? What is it doing? Commented Apr 26, 2012 at 16:32

2 Answers 2

2

You subprocess.call probably blocked on whatever your command was. I doubt its your python script, but rather whatever the shell command might be (taking too long).

You can tell if your command is completing or not by checking the return code:

print subprocess.call(["command","param"])

It should print 0 if it was successful, or raise an exception if the command has problems. But if you never see consecutive prints, then its never returning from the call.

Sign up to request clarification or add additional context in comments.

1 Comment

This was my mistake for immediately blaming the Python script. I think you may be right. I'm outputting the result into a log file to try and spot the error. Cheers!
1

Try subprocess.Popen if you don't need to wait for the command to complete.

From the docs,

subprocess.call: Run the command described by args. Wait for command to complete, then return the returncode attribute.

2 Comments

While this will solve the problem of blocking, it still wouldn't address that his commands aren't returning, and he will just end up stacking up hanging processes if he uses Popen.
True. It partially depends on what command he's calling, probably best to get the return code with call though.

Your Answer

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.