shutdown_event
API
=> 332e57006dfdbc813353722e1b4349a63c6a9886
[1mdiff --git a/gmcapsule/gemini.py b/gmcapsule/gemini.py[m [1mindex e80183e..e818a82 100644[m [1m--- a/gmcapsule/gemini.py[m [1m+++ b/gmcapsule/gemini.py[m [36m@@ -441,8 +441,9 @@[m [mclass Context:[m response_queues=None):[m self.cfg = cfg[m self.is_quiet = True[m [31m- self.shutdown_events = [][m self.allow_extension_workers = allow_extension_workers[m [32m+[m[32m if allow_extension_workers:[m [32m+[m[32m self.shutdown = threading.Event()[m self.hostnames = cfg.hostnames()[m self.entrypoints = {'gemini': {}, 'titan': {}}[m for proto in ['gemini', 'titan']:[m [36m@@ -468,24 +469,16 @@[m [mclass Context:[m """[m return self.allow_extension_workers[m [m [31m- def add_shutdown_event(self, event):[m [32m+[m[32m def shutdown_event(self):[m """[m [31m- Registers a shutdown event. Extension modules must call this to[m [31m- get notified when the server is being shut down.[m [31m-[m [31m- Args:[m [31m- event (threading.Event): Event that is set when the server is[m [31m- shutting down. Background workers must wait on this and stop[m [31m- when the event is set.[m [32m+[m[32m Returns:[m [32m+[m[32m threading.Event: Extension modules must check this to be notified[m [32m+[m[32m when the server is being shut down.[m """[m if not self.is_background_work_allowed():[m raise Exception("background work not allowed")[m # This is used in a parser thread that is allowed to launch workers.[m [31m- return self.shutdown_events.append(event)[m [31m-[m [31m- def set_shutdown(self):[m [31m- for event in self.shutdown_events:[m [31m- event.set()[m [32m+[m[32m return self.shutdown[m [m def set_quiet(self, is_quiet):[m self.is_quiet = is_quiet[m [36m@@ -844,9 +837,7 @@[m [mclass Server:[m self.context.set_session_id(session_id)[m [m # Spawn the worker threads.[m [31m- #self.parser_shutdown_event = threading.Event()[m self.parser_queue = queue.Queue()[m [31m- #self.handler_shutdown_event = mp.Event()[m self.handler_queue = mp.Queue()[m self.init_parser_context()[m self.parsers = [][m [36m@@ -955,7 +946,7 @@[m [mclass Server:[m print(len(self.parsers), 'parser(s) and', len(self.handlers), 'handler(s) started')[m [m def stop_workers(self):[m [31m- self.parser_context.set_shutdown()[m [32m+[m[32m self.parser_context.shutdown.set()[m [m # Stop parsers first so all ongoing handler processes get to finish, and no new[m # requests can come in.[m [36m@@ -972,4 +963,4 @@[m [mclass Server:[m print(len(self.parsers), 'parser(s) and', len(self.handlers), 'handler(s) stopped')[m self.parsers = [][m self.handlers = [][m [31m- self.parser_context.shutdown_events = [][m [32m+[m[32m self.parser_context.shutdown.clear()[m
text/gemini; charset=utf-8
This content has been proxied by September (ba2dc).