Delay a computation in another thread

Steve D'Aprano steve+python at pearwood.info
Sat Sep 2 06:59:35 EDT 2017


On Sat, 2 Sep 2017 08:53 pm, Steve D'Aprano wrote:

> I want to delay a computation and then print it, in the REPL (interactive
> interpreter). I have something like this:
[...]
> The other problem is that if I exit the REPL while a Timer is still active, it
> freezes until the time has run before exiting. I know you can't kill a thread
> from the main thread, but is there a way for the Timer to see that the
> interpreter is shutting down and shut itself down?

Oh! I see Timer objects have a cancel method. So I just need an atexit callback
function that calls cancel to each of the Timer threads.

-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list