0

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 .

Python P
  • 25
  • 6
  • This has already been answered. https://stackoverflow.com/questions/1191374/using-module-subprocess-with-timeout – abak1802 Jan 23 '21 at 02:28

1 Answers1

1

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.

Filipe
  • 169
  • 5
  • No problem. Just keep in mind that the process will continue. If you want to stop it, i will need to call l.kill() method. – Filipe Jan 22 '21 at 20:51