From 92394cac27b28dd159e6c5b37e0b82153a94c613 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Bokros?= Date: Tue, 5 Dec 2017 18:36:26 +0100 Subject: [PATCH] Fix handling exhausted generators --- src/event_handlers/event_handler_main.py | 1 - src/event_handlers/stateful_event_handler.py | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/event_handlers/event_handler_main.py b/src/event_handlers/event_handler_main.py index 3875054..52f5130 100644 --- a/src/event_handlers/event_handler_main.py +++ b/src/event_handlers/event_handler_main.py @@ -71,7 +71,6 @@ def login_handler(data, component): def source_code_handler(data, event_handler): - event_handler.unsubscribe(data['anchor']) yield (data['anchor'], source_code.get_source_code(authorize_login, strip_comments=True)) diff --git a/src/event_handlers/stateful_event_handler.py b/src/event_handlers/stateful_event_handler.py index 5ba3bfe..f03e105 100644 --- a/src/event_handlers/stateful_event_handler.py +++ b/src/event_handlers/stateful_event_handler.py @@ -21,7 +21,11 @@ class StatefulEventHandler(EventHandlerBase): data_json = json.loads(message) if self.generator is None: self.generator = self.event_handler_function(data_json, self) - response_anchor, response_data = next(self.generator) + try: + response_anchor, response_data = next(self.generator) + except StopIteration: + self.reset() + return if response_anchor not in self.subscriptions: self.subscriptions.add(response_anchor) self.zmq_sub_socket.setsockopt_string(zmq.SUBSCRIBE, response_anchor)