Re: Delay a computation in another thread

2017-09-08 Thread eryk sun
On Fri, Sep 8, 2017 at 10:03 AM, Thomas Jollans wrote: > On 2017-09-08 16:49, Steve D'Aprano wrote: > >> Sorry for the long delay in replying to this, but if I set its daemon >> attribute, >> won't that mean it will live on after the interpreter shuts down? >> >> Also, what happens if it tries to

Re: Delay a computation in another thread

2017-09-08 Thread Thomas Jollans
On 2017-09-08 16:49, Steve D'Aprano wrote: > On Sun, 3 Sep 2017 03:03 am, MRAB wrote: > >> 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

Re: Delay a computation in another thread

2017-09-08 Thread Ethan Furman
On 09/08/2017 07:49 AM, Steve D'Aprano wrote: On Sun, 3 Sep 2017 03:03 am, MRAB wrote: Timer is a subclass of Thread, so you can set its .daemon attribute. Sorry for the long delay in replying to this, but if I set its daemon attribute, won't that mean it will live on after the interpreter s

Re: Delay a computation in another thread

2017-09-08 Thread Steve D'Aprano
On Sun, 3 Sep 2017 03:03 am, MRAB wrote: > 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

Re: Delay a computation in another thread

2017-09-02 Thread Terry Reedy
On 9/2/2017 6:53 AM, Steve D'Aprano wrote: I want to delay a computation and then print it, in the REPL (interactive interpreter). I have something like this: import time from threading import Timer def do_work(): x = 2 + 2 print("It is", time.asctime(), "and 2+2 is", x) def schedul

Re: Delay a computation in another thread

2017-09-02 Thread eryk sun
On Sat, Sep 2, 2017 at 5:53 AM, Steve D'Aprano wrote: > > The problem is that after the message is printed, the REPL's prompt is > disrupted. This is especially annoying when I'm in the middle of typing a > line. > This is just a cosmetic flaw, but it would be nice if I could tell Python to > red

Re: Delay a computation in another thread

2017-09-02 Thread MRAB
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, i

Re: Delay a computation in another thread

2017-09-02 Thread Chris Angelico
On Sat, Sep 2, 2017 at 8:53 PM, Steve D'Aprano wrote: > The problem is that after the message is printed, the REPL's prompt is > disrupted. This is especially annoying when I'm in the middle of typing a > line. > This is just a cosmetic flaw, but it would be nice if I could tell Python to > redra

Re: Delay a computation in another thread

2017-09-02 Thread Steve D'Aprano
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

Delay a computation in another thread

2017-09-02 Thread Steve D'Aprano
I want to delay a computation and then print it, in the REPL (interactive interpreter). I have something like this: import time from threading import Timer def do_work(): x = 2 + 2 print("It is", time.asctime(), "and 2+2 is", x) def schedule_work(): Timer(60, do_work, ()).start() #