timers in threaded application

dieter dieter at handshake.de
Fri Jan 13 04:23:51 EST 2017


Skip Montanaro <skip.montanaro at gmail.com> writes:
> ...
> I still need timers, and for the moment I'm stuck with this package's event
> loop. What options do I have?

If the activities are really run in separate threads (such that
an event processing can take arbitrary time without much
affecting the processing of other events) and "select.select"
is available on your platform (e.g. some *nix* platform),
you might be able to use its "timeout" parameter. This is
particularly useful when what you want to timeout are I/O operations.

If what you want to timeout are not I/O operations, you can have a
look at "threading.Timer". It uses a separate thread, lets it wait
a specified time and then starts a specified function, unless
"cancel"ed. In this case, you must find some way to abort a pending
event processing due to a timeout and let the timer function use it
for abortion.



More information about the Python-list mailing list