summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins/xep_0323/timerreset.py
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2014-07-17 14:19:04 +0200
committerFlorent Le Coz <louiz@louiz.org>2014-07-17 14:19:04 +0200
commit5ab77c745270d7d5c016c1dc7ef2a82533a4b16e (patch)
tree259377cc666f8b9c7954fc4e7b8f7a912bcfe101 /sleekxmpp/plugins/xep_0323/timerreset.py
parente5582694c07236e6830c20361840360a1dde37f3 (diff)
downloadslixmpp-5ab77c745270d7d5c016c1dc7ef2a82533a4b16e.tar.gz
slixmpp-5ab77c745270d7d5c016c1dc7ef2a82533a4b16e.tar.bz2
slixmpp-5ab77c745270d7d5c016c1dc7ef2a82533a4b16e.tar.xz
slixmpp-5ab77c745270d7d5c016c1dc7ef2a82533a4b16e.zip
Rename to slixmpp
Diffstat (limited to 'sleekxmpp/plugins/xep_0323/timerreset.py')
-rw-r--r--sleekxmpp/plugins/xep_0323/timerreset.py64
1 files changed, 0 insertions, 64 deletions
diff --git a/sleekxmpp/plugins/xep_0323/timerreset.py b/sleekxmpp/plugins/xep_0323/timerreset.py
deleted file mode 100644
index 578f1efe..00000000
--- a/sleekxmpp/plugins/xep_0323/timerreset.py
+++ /dev/null
@@ -1,64 +0,0 @@
-"""
- SleekXMPP: The Sleek XMPP Library
- Implementation of xeps for Internet of Things
- http://wiki.xmpp.org/web/Tech_pages/IoT_systems
- Copyright (C) 2013 Sustainable Innovation, Joachim.lindborg@sust.se, bjorn.westrom@consoden.se
- This file is part of SleekXMPP.
-
- See the file LICENSE for copying permission.
-"""
-from threading import Thread, Event, Timer
-import time
-
-def TimerReset(*args, **kwargs):
- """ Global function for Timer """
- return _TimerReset(*args, **kwargs)
-
-
-class _TimerReset(Thread):
- """Call a function after a specified number of seconds:
-
- t = TimerReset(30.0, f, args=[], kwargs={})
- t.start()
- t.cancel() # stop the timer's action if it's still waiting
- """
-
- def __init__(self, interval, function, args=[], kwargs={}):
- Thread.__init__(self)
- self.interval = interval
- self.function = function
- self.args = args
- self.kwargs = kwargs
- self.finished = Event()
- self.resetted = True
-
- def cancel(self):
- """Stop the timer if it hasn't finished yet"""
- self.finished.set()
-
- def run(self):
- #print "Time: %s - timer running..." % time.asctime()
-
- while self.resetted:
- #print "Time: %s - timer waiting for timeout in %.2f..." % (time.asctime(), self.interval)
- self.resetted = False
- self.finished.wait(self.interval)
-
- if not self.finished.isSet():
- self.function(*self.args, **self.kwargs)
- self.finished.set()
- #print "Time: %s - timer finished!" % time.asctime()
-
- def reset(self, interval=None):
- """ Reset the timer """
-
- if interval:
- #print "Time: %s - timer resetting to %.2f..." % (time.asctime(), interval)
- self.interval = interval
- else:
- #print "Time: %s - timer resetting..." % time.asctime()
- pass
-
- self.resetted = True
- self.finished.set()
- self.finished.clear()