aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArksine <arksine.code@gmail.com>2020-07-06 05:50:16 -0400
committerKevinOConnor <kevin@koconnor.net>2020-07-06 12:57:50 -0400
commitbfbdc04c02fb3c4b58e38e6d534024a4987e9aff (patch)
treea5fd864c72521c1bc07c178a279ce26b35663783
parent65ade083b2683bc4edc329661a4178577d7224e3 (diff)
downloadkutter-bfbdc04c02fb3c4b58e38e6d534024a4987e9aff.tar.gz
kutter-bfbdc04c02fb3c4b58e38e6d534024a4987e9aff.tar.xz
kutter-bfbdc04c02fb3c4b58e38e6d534024a4987e9aff.zip
webhooks: process request handlers using a Reactor Callback
This prevents _process_data from blocking and becoming reentrant. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
-rw-r--r--klippy/webhooks.py24
1 files changed, 7 insertions, 17 deletions
diff --git a/klippy/webhooks.py b/klippy/webhooks.py
index 0379e3ab..1decdce5 100644
--- a/klippy/webhooks.py
+++ b/klippy/webhooks.py
@@ -98,7 +98,6 @@ class ServerConnection:
# Klippy Connection
self.fd = self.fd_handle = self.mutex = None
self.is_server_connected = False
- self.is_busy = False
self.partial_data = ""
is_fileoutput = (printer.get_start_args().get('debugoutput')
is not None)
@@ -151,29 +150,20 @@ class ServerConnection:
requests = data.split('\x03')
requests[0] = self.partial_data + requests[0]
self.partial_data = requests.pop()
- if self.is_busy:
- if len(requests > 20):
- self.reactor.unregister_fd(self.fd_handle)
- self.fd_handle = None
- return
- self.is_busy = True
for req in requests:
logging.debug(
- "ServerConnection: Request received from Moonraker %s" % (req))
+ "ServerConnection: Request received: %s" % (req))
try:
- decoded_req = json_loads_byteified(req)
- self._process_request(decoded_req)
+ web_request = WebRequest(json_loads_byteified(req))
except Exception:
logging.exception(
- "ServerConnection: Error processing Server Request %s"
+ "ServerConnection: Error decoding Server Request %s"
% (req))
- self.is_busy = False
- if self.fd_handle is None:
- self.fd_handle = self.reactor.register_fd(
- self.fd, self.process_received)
+ continue
+ self.reactor.register_callback(
+ lambda e, s=self: s._process_request(web_request))
- def _process_request(self, req):
- web_request = WebRequest(req)
+ def _process_request(self, web_request):
try:
func = self.webhooks.get_callback(
web_request.get_path())