diff --git a/src/octoprint/comm/protocol/reprap/__init__.py b/src/octoprint/comm/protocol/reprap/__init__.py index d50480565..9cc164b75 100644 --- a/src/octoprint/comm/protocol/reprap/__init__.py +++ b/src/octoprint/comm/protocol/reprap/__init__.py @@ -125,7 +125,7 @@ class RepRapProtocol(Protocol): self._send_queue = CommandQueue() - self._clear_for_send = CountedEvent() + self._clear_for_send = CountedEvent(max=20) self._force_checksum = True self._wait_for_start = False @@ -808,10 +808,9 @@ class RepRapProtocol(Protocol): # we just got a send timeout, so we'll just try again on the next loop iteration continue - # decrease the clear_for_send counter - self._clear_for_send.clear() - if not sent or self._rx_cache_size <= 0: + # decrease the clear_for_send counter + self._clear_for_send.clear() self._clear_for_send.wait() def _send_from_queue(self): diff --git a/src/octoprint/util/__init__.py b/src/octoprint/util/__init__.py index b032930a9..acedc9f5a 100644 --- a/src/octoprint/util/__init__.py +++ b/src/octoprint/util/__init__.py @@ -284,8 +284,9 @@ def address_for_client(host, port): class CountedEvent(object): - def __init__(self, value=0): + def __init__(self, value=0, max=None): self._counter = 0 + self._max = max self._mutex = threading.Lock() self._event = threading.Event() @@ -315,6 +316,8 @@ class CountedEvent(object): self._counter = 0 self._event.clear() else: + if self._max is not None and self._counter > self._max: + self._counter = self._max self._event.set()