From 332e57006dfdbc813353722e1b4349a63c6a9886 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= jaakko.keranen@iki.fi
Date: Sat, 17 Jun 2023 10:51:25 +0300
Subject: [PATCH 1/1] Restored previous shutdown_event
API
gmcapsule/gemini.py | 27 +++++++++------------------
1 file changed, 9 insertions(+), 18 deletions(-)
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
"""
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)
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()
--
2.25.1
text/plain
This content has been proxied by September (3851b).