From af2316233ad66517dc7b3bb710d5077f9347ede7 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 19 May 2023 20:13:18 +0200 Subject: [PATCH] sse: gotta use a special version of zeromq (zmq.green) when in gevent context --- moulinette/interfaces/api.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/moulinette/interfaces/api.py b/moulinette/interfaces/api.py index 92488623..06f146dc 100644 --- a/moulinette/interfaces/api.py +++ b/moulinette/interfaces/api.py @@ -352,7 +352,7 @@ class _ActionsMapPlugin: def sse(self): import time - import zmq + import zmq.green as zmq # FIXME : check auth... @@ -367,13 +367,14 @@ class _ActionsMapPlugin: # Set client-side auto-reconnect timeout, ms. yield 'retry: 100\n\n' - while True: - try: + try: + while True: if sub.poll(10, zmq.POLLIN): _, msg = sub.recv_multipart() yield 'data: ' + str(msg.decode()) + '\n\n' - except KeyboardInterrupt: - break + finally: + sub.close() + ctx.term() def process(self, _route, arguments={}): """Process the relevant action for the route