how to set timeout for os.popen

MRAB python at mrabarnett.plus.com
Sun Apr 15 14:14:18 EDT 2018


On 2018-04-15 12:01, Ho Yeung Lee wrote:
> while 1:
> runner = os.popen("tracert -d www.hello.com")
> o=runner.read()
> print(o)
> runner.close()
> runner = os.popen("tracert -d www.hello.com")
> o=runner.read()
> print(o)
> runner.close()
> runner = os.popen("tracert -d www.hello.com")
> o=runner.read()
> print(o)
> runner.close()
> 
> 
> after running over 1 hour, it stop and not return in one of tracert
> 
> how to set timeout and know that this is timeout?
> 
Try using the 'subprocess' module instead.


More information about the Python-list mailing list