Python: Setting an alarm outside of the main thread

Go To StackoverFlow.com

2

I know you can use signal.alarm() to schedule alarms in your main thread, but is there a way to do something like this in a thread that isn't your main thread, since these threads can't receive signals? I need to schedule something to happen 5 minutes in the future.

2012-04-05 21:43
by garsh0p
Is there a particular reason you want to use signals rather than using something like the Timer class - Jason LeBrun 2012-04-05 21:59
No, that's exactly what I was looking for though :) I just wasn't aware of any alternatives - garsh0p 2012-04-05 22:06


1

Use Timer instead of signals. Dealing with signals will open up lots of cans of worms, so you should avoid it whenever you can. In this case, it sounds like you can.

2012-04-05 22:09
by Jason LeBrun


0

You can use threading.Event to notify your threads about events. Have a look at threading.Timer as well.

2012-04-05 21:57
by Maksym Polshcha
I'm using threading.Event right now, but I need to set an alarm to set() the event 5 minutes into the future somehow - garsh0p 2012-04-05 22:05
@garsh0p Something like threading.Timer - Maksym Polshcha 2012-04-05 22:09
Ads