Reputation: 25
I hope that everyone is okay :
i just would like to write a code in python for checking my server command (df -h ) , if this command will not give result for 2 minutes , an error message will write to me , otherwise will pass , any idea how can implement this using python .
Upvotes: 0
Views: 58
Reputation: 169
Did you try the wait method for a subprocess object? like this example:
from subprocess import Popen, PIPE
#call sleep with arg = 5 seconds
l = Popen(['sleep','5'])
#wait for 4 seconds
l.wait(4)
If you run this, you will have an error after 4 seconds, but if you change the argument for the wait function for 6 for example, it wont return any error.
Upvotes: 1