Improved cancelling by new lock, should make it even more snappier

This commit is contained in:
Gina Häußge committed 2014-11-13 13:08:11 +01:00
1 parent 16d156b530
commit a0a6f958d9
2 files changed
+11 -3

No files matched your search

@@ -825,7 +825,8 @@ class RepRapProtocol(Protocol):
try:
with self._send_lock:
sent = self._send_from_queue()
with self._send_queue.clearlock:
sent = self._send_from_queue()
except SendTimeout:
# we just got a send timeout, so we'll just try again on the next loop iteration
continue
+9 -2
View File
@@ -144,16 +144,20 @@ class CommandQueueEntry(object):
return other + self._size
def __repr__(self):
return "CommandQueueEntry({command},line_number={line_number},prepared={prepared})".format(command=repr(self.command), line_number=self.line_number, prepared=self.prepared)
return "CommandQueueEntry({command},prepared={prepared})".format(command=repr(self.command), prepared=self.prepared)
class SpecialCommandQueueEntry(CommandQueueEntry):
TYPE_JOBDONE = "JobDone"
TYPE_JOBCANCELLED = "JobCancelled"
def __init__(self, type):
CommandQueueEntry.__init__(self, CommandQueueEntry.PRIORITY_NORMAL, None)
self.type = type
def __repr__(self):
return "SpecialCommandQueueEntry(type={type})".format(type=self.type)
class CommandQueue(Queue.Queue):
'''Variant of Queue that retrieves open entries in priority order (lowest first, followed by addition order).
@@ -168,6 +172,9 @@ class CommandQueue(Queue.Queue):
self.lookup = {}
self.counter = itertools.count()
import threading
self.clearlock = threading.RLock()
def _qsize(self, len=len):
return len(self.queue)
@@ -228,7 +235,7 @@ class CommandQueue(Queue.Queue):
matcher = lambda x: True
cleared = []
with self.mutex:
with self.clearlock:
for entry in self.queue[:]:
priority, counter, item = entry
if matcher(item):