From a0a6f958d9f9e1bb8179b7a41f9e6a63d67bf42a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 13 Nov 2014 13:08:11 +0100 Subject: [PATCH] Improved cancelling by new lock, should make it even more snappier --- src/octoprint/comm/protocol/reprap/__init__.py | 3 ++- src/octoprint/comm/protocol/reprap/util.py | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/octoprint/comm/protocol/reprap/__init__.py b/src/octoprint/comm/protocol/reprap/__init__.py index 85925590b..1ed362d84 100644 --- a/src/octoprint/comm/protocol/reprap/__init__.py +++ b/src/octoprint/comm/protocol/reprap/__init__.py @@ -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 diff --git a/src/octoprint/comm/protocol/reprap/util.py b/src/octoprint/comm/protocol/reprap/util.py index b99e7a35c..311303974 100644 --- a/src/octoprint/comm/protocol/reprap/util.py +++ b/src/octoprint/comm/protocol/reprap/util.py @@ -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):