GmCapsule [main]

Restored previous shutdown_event API

=> 332e57006dfdbc813353722e1b4349a63c6a9886

diff --git a/gmcapsule/gemini.py b/gmcapsule/gemini.py
index e80183e..e818a82 100644
--- a/gmcapsule/gemini.py
+++ b/gmcapsule/gemini.py
@@ -441,8 +441,9 @@ class Context:
                  response_queues=None):
         self.cfg = cfg
         self.is_quiet = True
-        self.shutdown_events = []
         self.allow_extension_workers = allow_extension_workers
+        if allow_extension_workers:
+            self.shutdown = threading.Event()
         self.hostnames = cfg.hostnames()
         self.entrypoints = {'gemini': {}, 'titan': {}}
         for proto in ['gemini', 'titan']:
@@ -468,24 +469,16 @@ class Context:
         """
         return self.allow_extension_workers
 
-    def add_shutdown_event(self, event):
+    def shutdown_event(self):
         """
-        Registers a shutdown event. Extension modules must call this to
-        get notified when the server is being shut down.
-
-        Args:
-            event (threading.Event): Event that is set when the server is
-            shutting down. Background workers must wait on this and stop
-            when the event is set.
+        Returns:
+            threading.Event: Extension modules must check this to be notified
+            when the server is being shut down.
         """
         if not self.is_background_work_allowed():
             raise Exception("background work not allowed")
         # This is used in a parser thread that is allowed to launch workers.
-        return self.shutdown_events.append(event)
-
-    def set_shutdown(self):
-        for event in self.shutdown_events:
-            event.set()
+        return self.shutdown
 
     def set_quiet(self, is_quiet):
         self.is_quiet = is_quiet
@@ -844,9 +837,7 @@ class Server:
         self.context.set_session_id(session_id)
 
         # Spawn the worker threads.
-        #self.parser_shutdown_event = threading.Event()
         self.parser_queue = queue.Queue()
-        #self.handler_shutdown_event = mp.Event()
         self.handler_queue = mp.Queue()
         self.init_parser_context()
         self.parsers = []
@@ -955,7 +946,7 @@ class Server:
         print(len(self.parsers), 'parser(s) and', len(self.handlers), 'handler(s) started')
 
     def stop_workers(self):
-        self.parser_context.set_shutdown()
+        self.parser_context.shutdown.set()
 
         # Stop parsers first so all ongoing handler processes get to finish, and no new
         # requests can come in.
@@ -972,4 +963,4 @@ class Server:
         print(len(self.parsers), 'parser(s) and', len(self.handlers), 'handler(s) stopped')
         self.parsers = []
         self.handlers = []
-        self.parser_context.shutdown_events = []
+        self.parser_context.shutdown.clear()
Proxy Information
Original URL
gemini://git.skyjake.fi/gmcapsule/main/cdiff/332e57006dfdbc813353722e1b4349a63c6a9886
Status Code
Success (20)
Meta
text/gemini; charset=utf-8
Capsule Response Time
29.538838 milliseconds
Gemini-to-HTML Time
0.351651 milliseconds

This content has been proxied by September (ba2dc).