Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
210 views
in Technique[技术] by (71.8m points)

Code for waiting my previous condition for 2 minutes if not work , then raise an error message using python

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 .

question from:https://stackoverflow.com/questions/65851117/code-for-waiting-my-previous-condition-for-2-minutes-if-not-work-then-raise-an

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...