how to set timeout for os.popen

Jason Friedman jsf80238 at gmail.com
Sun Apr 15 12:25:09 EDT 2018


>
> 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?
>

There are a number of answers on Stackoverflow, for example
https://stackoverflow.com/questions/492519/timeout-on-a-function-call.  The
first few answers there seem to be Nix-specific, with OS-agnostic
multiprocessing answers below.



More information about the Python-list mailing list