Reputation: 1600
I'm having trouble figuring out how to call a function asynchronously in X time as a one-off without needing to clutter the app with a bunch of class variables to keep track of the timer or cancel the timer after the function is called. Javascript can do this the easiest, so I'll show what I'd like to do in python using JS
setTimeout(function()
{
//Do something in 1 second
}, 1000);
Basically, what I have now is:
class NeedyObject(QWidget):
theTimer = None
def process(self):
self.theTimer =Timer(1,self.processCallback)
self.theTimer.start()
def processCallback(self):
self.theTimer.cancel()
#do something
I need to fire these one-off calls several times for a lot of different reasons and keeping track of every timer to cancel it isn't the way I'd like to do it.
How can I get this JS concept into Python?
Upvotes: 0
Views: 61
Reputation: 685
I noticed QWidget
as a parameter to NeedyObject
. If you're using Qt with Python bindings, maybe you could leverage a single-shot QTimer.
Upvotes: 1