ClearableQueue redundant with self.close

Closing the printer connection and then reopening (when the users clicks
connect) will create a new fresh MachineCom object so the queues will
start out empty.  Plus ClearableQueue was even more tied to the Queue
implementation that the current _get/_put overrides.
This commit is contained in:
Mark Walker 2015-08-22 18:15:54 -07:00
parent 3d1d745581
commit e7584cdaac

View file

@ -223,7 +223,7 @@ class MachineCom(object):
self._temp = {} self._temp = {}
self._bedTemp = None self._bedTemp = None
self._tempOffsets = dict() self._tempOffsets = dict()
self._commandQueue = ClearableQueue() self._commandQueue = queue.Queue()
self._currentZ = None self._currentZ = None
self._heatupWaitStartTime = None self._heatupWaitStartTime = None
self._heatupWaitTimeLost = 0.0 self._heatupWaitTimeLost = 0.0
@ -1820,17 +1820,12 @@ class MachineCom(object):
self._lastLines.clear() self._lastLines.clear()
self._resendDelta = None self._resendDelta = None
def _gcode_M112_queuing(self, cmd, cmd_type=None): def _gcode_M112_queuing(self, cmd, cmd_type=None):
# emergency stop, tell the printer right now and clear the queues # emergency stop, tell the printer right now and clear the queues
# jump the queue with the M112 # jump the queue with the M112
self._doSendWithoutChecksum("M112") self._doSendWithoutChecksum("M112")
self._doSendWithChecksum("M112", self._currentLine) self._doSendWithChecksum("M112", self._currentLine)
# of course, these clears are too late to get the one that another thread
# is in between get and task_done
self._commandQueue.clear()
self._send_queue.clear()
# close to reset host state # close to reset host state
self._errorValue = "Closing serial port due to emergency stop M112." self._errorValue = "Closing serial port due to emergency stop M112."
self._log(self._errorValue) self._log(self._errorValue)
@ -2067,27 +2062,10 @@ class StreamingGcodeFileInformation(PrintingGcodeFileInformation):
return self._remoteFilename return self._remoteFilename
class ClearableQueue(queue.Queue): class TypedQueue(queue.Queue):
def clear(self):
self.all_tasks_done.acquire()
try:
self._clear()
finally:
self.all_tasks_done.release()
def _clear(self):
count = len(self.queue)
self.queue.clear()
self.unfinished_tasks -= count
if (self.unfinished_tasks <= 0):
self.all_tasks_done.notify_all();
self.not_full.notify()
class TypedQueue(ClearableQueue):
def __init__(self, maxsize=0): def __init__(self, maxsize=0):
ClearableQueue.__init__(self, maxsize=maxsize) queue.Queue.__init__(self, maxsize=maxsize)
self._lookup = [] self._lookup = []
def _put(self, item): def _put(self, item):
@ -2099,10 +2077,10 @@ class TypedQueue(ClearableQueue):
else: else:
self._lookup.append(cmd_type) self._lookup.append(cmd_type)
ClearableQueue._put(self, item) queue.Queue._put(self, item)
def _get(self): def _get(self):
item = ClearableQueue._get(self) item = queue.Queue._get(self)
if isinstance(item, tuple) and len(item) == 3: if isinstance(item, tuple) and len(item) == 3:
cmd, line, cmd_type = item cmd, line, cmd_type = item
@ -2111,10 +2089,6 @@ class TypedQueue(ClearableQueue):
return item return item
def _clear(self):
ClearableQueue._clear(self)
self._lookup = []
class TypeAlreadyInQueue(Exception): class TypeAlreadyInQueue(Exception):
def __init__(self, t, *args, **kwargs): def __init__(self, t, *args, **kwargs):