Delay a computation in another thread
MRAB
python at mrabarnett.plus.com
Sat Sep 2 13:03:25 EDT 2017
On 2017-09-02 11:59, Steve D'Aprano wrote:
> 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.
>
Timer is a subclass of Thread, so you can set its .daemon attribute.
More information about the Python-list
mailing list