summaryrefslogtreecommitdiff
path: root/sleekxmpp/xmlstream
diff options
context:
space:
mode:
authorAnton Ryzhov <anton@ryzhov.me>2013-06-20 12:41:46 +0400
committerAnton Ryzhov <anton@ryzhov.me>2013-06-20 18:30:07 +0400
commit7430a8ca401a4ece1b9e717e3f45c9c93dda6960 (patch)
treee1594d417b94459eefafcd69412d8c60c94f999b /sleekxmpp/xmlstream
parentbaf9aaf26c80c87e770cdf35b1fa4fe231663246 (diff)
downloadslixmpp-7430a8ca401a4ece1b9e717e3f45c9c93dda6960.tar.gz
slixmpp-7430a8ca401a4ece1b9e717e3f45c9c93dda6960.tar.bz2
slixmpp-7430a8ca401a4ece1b9e717e3f45c9c93dda6960.tar.xz
slixmpp-7430a8ca401a4ece1b9e717e3f45c9c93dda6960.zip
Some optimizations in scheduler
Diffstat (limited to 'sleekxmpp/xmlstream')
-rw-r--r--sleekxmpp/xmlstream/scheduler.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/sleekxmpp/xmlstream/scheduler.py b/sleekxmpp/xmlstream/scheduler.py
index bef8f5e5..d57b2271 100644
--- a/sleekxmpp/xmlstream/scheduler.py
+++ b/sleekxmpp/xmlstream/scheduler.py
@@ -139,24 +139,26 @@ class Scheduler(object):
self.run = True
try:
while self.run and not self.stop.is_set():
- wait = 0.1
updated = False
if self.schedule:
wait = self.schedule[0].next - time.time()
+ else:
+ wait = 0.1
try:
if wait <= 0.0:
newtask = self.addq.get(False)
else:
- if wait >= 3.0:
+ if wait > 3.0:
wait = 3.0
newtask = None
elapsed = 0
- while not self.stop.is_set() and \
+ while self.run and \
+ not self.stop.is_set() and \
newtask is None and \
elapsed < wait:
newtask = self.addq.get(True, 0.1)
elapsed += 0.1
- except QueueEmpty:
+ 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
relevant = itertools.takewhile(
@@ -174,11 +176,11 @@ class Scheduler(object):
# only need to resort tasks if a repeated task has
# been kept in the list.
updated = True
- else:
- updated = True
+ else: # Add new task
self.schedule_lock.acquire()
if newtask is not None:
self.schedule.append(newtask)
+ updated = True
finally:
if updated:
self.schedule.sort(key=lambda task: task.next)