I'm trying to develop a script where a ping command hits 100ms it stops. Is there an easy way to do this?
It would be something like:
import subprocess
command = ['ping', '-c', '4', '8.8.8.8']
proc = subprocess.run(command)
if time > 100:
   break
I'm trying to develop a script where a ping command hits 100ms it stops. Is there an easy way to do this?
It would be something like:
import subprocess
command = ['ping', '-c', '4', '8.8.8.8']
proc = subprocess.run(command)
if time > 100:
   break
 
    
    Depending on your version of Python, it looks like subprocess.run() has a timeout (measured in seconds) keyword argument that does what you are looking for:
proc = subprocess.run(command, timeout=0.1)
The timeout argument is passed to Popen.communicate(). If the timeout expires, the child process will be killed and waited for. The TimeoutExpired exception will be re-raised after the child process has terminated.
