mirror of
https://github.com/rembo10/headphones.git
synced 2026-07-20 16:03:59 +01:00
Potential fix for #2055
This commit is contained in:
+5
-6
@@ -39,12 +39,12 @@ class TimedLock(object):
|
|||||||
sleep_amount = self.minimum_delta - delta
|
sleep_amount = self.minimum_delta - delta
|
||||||
if sleep_amount >= 0:
|
if sleep_amount >= 0:
|
||||||
# zero sleeps give the cpu a chance to task-switch
|
# zero sleeps give the cpu a chance to task-switch
|
||||||
headphones.logger.info('Sleeping %s (interval)', sleep_amount)
|
headphones.logger.debug('Sleeping %s (interval)', sleep_amount)
|
||||||
time.sleep(sleep_amount)
|
time.sleep(sleep_amount)
|
||||||
while not self.queue.empty():
|
while not self.queue.empty():
|
||||||
try:
|
try:
|
||||||
seconds = self.queue.get(False)
|
seconds = self.queue.get(False)
|
||||||
headphones.logger.info('Sleeping %s (queued)', seconds)
|
headphones.logger.debug('Sleeping %s (queued)', seconds)
|
||||||
time.sleep(seconds)
|
time.sleep(seconds)
|
||||||
except Queue.Empty:
|
except Queue.Empty:
|
||||||
continue
|
continue
|
||||||
@@ -59,15 +59,14 @@ class TimedLock(object):
|
|||||||
|
|
||||||
def snooze(self, seconds):
|
def snooze(self, seconds):
|
||||||
"""
|
"""
|
||||||
Asynchronously add time to the next request.
|
Asynchronously add time to the next request. Can be called outside
|
||||||
Can be called outside
|
|
||||||
of the lock context, but it is possible for the next lock holder
|
of the lock context, but it is possible for the next lock holder
|
||||||
to not check the queue until after something adds time to it.
|
to not check the queue until after something adds time to it.
|
||||||
"""
|
"""
|
||||||
# we use a queue so that we don't have to synchronize
|
# We use a queue so that we don't have to synchronize
|
||||||
# across threads and with or without locks
|
# across threads and with or without locks
|
||||||
headphones.logger.info('Adding %s to queue', seconds)
|
headphones.logger.info('Adding %s to queue', seconds)
|
||||||
self.queue.add(seconds)
|
self.queue.put(seconds)
|
||||||
|
|
||||||
|
|
||||||
class FakeLock(object):
|
class FakeLock(object):
|
||||||
|
|||||||
Reference in New Issue
Block a user