Fix handling exhausted generators

This commit is contained in:
Bálint Bokros 2017-12-05 18:36:26 +01:00
parent ad89c8fb57
commit 92394cac27
2 changed files with 5 additions and 2 deletions

View File

@ -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))

View File

@ -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)