diff options
author | Anton Ryzhov <anton@ryzhov.me> | 2013-06-20 13:07:57 +0400 |
---|---|---|
committer | Anton Ryzhov <anton@ryzhov.me> | 2013-06-20 18:30:07 +0400 |
commit | 805f1c0e392b29dd335ea6b62b6c08a17a7f6e2c (patch) | |
tree | 23b007c40bffd2591e2115ebfd9332226154db0b /sleekxmpp/xmlstream/scheduler.py | |
parent | 7430a8ca401a4ece1b9e717e3f45c9c93dda6960 (diff) | |
download | slixmpp-805f1c0e392b29dd335ea6b62b6c08a17a7f6e2c.tar.gz slixmpp-805f1c0e392b29dd335ea6b62b6c08a17a7f6e2c.tar.bz2 slixmpp-805f1c0e392b29dd335ea6b62b6c08a17a7f6e2c.tar.xz slixmpp-805f1c0e392b29dd335ea6b62b6c08a17a7f6e2c.zip |
Use timeout constants instead of magic numbers in scheduler and event loop
Set default wait timeout as max() of previous values
Diffstat (limited to 'sleekxmpp/xmlstream/scheduler.py')
-rw-r--r-- | sleekxmpp/xmlstream/scheduler.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/sleekxmpp/xmlstream/scheduler.py b/sleekxmpp/xmlstream/scheduler.py index d57b2271..2efa7d1e 100644 --- a/sleekxmpp/xmlstream/scheduler.py +++ b/sleekxmpp/xmlstream/scheduler.py @@ -20,6 +20,11 @@ import itertools from sleekxmpp.util import Queue, QueueEmpty +#: The time in seconds to wait for events from the event queue, and also the +#: time between checks for the process stop signal. +WAIT_TIMEOUT = 1.0 + + log = logging.getLogger(__name__) @@ -120,6 +125,10 @@ class Scheduler(object): #: Lock for accessing the task queue. self.schedule_lock = threading.RLock() + #: The time in seconds to wait for events from the event queue, + #: and also the time between checks for the process stop signal. + self.wait_timeout = WAIT_TIMEOUT + def process(self, threaded=True, daemon=False): """Begin accepting and processing scheduled tasks. @@ -143,7 +152,7 @@ class Scheduler(object): if self.schedule: wait = self.schedule[0].next - time.time() else: - wait = 0.1 + wait = self.wait_timeout try: if wait <= 0.0: newtask = self.addq.get(False) @@ -156,8 +165,8 @@ class Scheduler(object): not self.stop.is_set() and \ newtask is None and \ elapsed < wait: - newtask = self.addq.get(True, 0.1) - elapsed += 0.1 + newtask = self.addq.get(True, self.wait_timeout) + elapsed += self.wait_timeout except QueueEmpty: # Time to run some tasks, and no new tasks to add. self.schedule_lock.acquire() # select only those tasks which are to be executed now |