aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiguel Jacq <mig@mig5.net>2023-05-30 16:19:37 +1000
committerMiguel Jacq <mig@mig5.net>2023-05-30 16:19:37 +1000
commite434c0463ce08f3dcaeb3fa37973135e3094caf5 (patch)
tree0f5cfe0d3015a937bb44f44788859a6451f5ddd6
parent9a19c47185289676e86f8bce1f0d54c941500da3 (diff)
downloadonionshare-e434c0463ce08f3dcaeb3fa37973135e3094caf5.tar.gz
onionshare-e434c0463ce08f3dcaeb3fa37973135e3094caf5.zip
Stop Waitress immediately rather than waiting
-rw-r--r--cli/onionshare_cli/web/web.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/cli/onionshare_cli/web/web.py b/cli/onionshare_cli/web/web.py
index 8dcee656..7da05509 100644
--- a/cli/onionshare_cli/web/web.py
+++ b/cli/onionshare_cli/web/web.py
@@ -372,7 +372,7 @@ class Web:
self.socketio.stop()
if self.waitress:
- self.waitress.close()
+ self.waitress_custom_shutdown()
def cleanup(self):
"""
@@ -385,3 +385,15 @@ class Web:
dir.cleanup()
self.cleanup_tempdirs = []
+
+ def waitress_custom_shutdown(self):
+ """Shutdown the Waitress server immediately"""
+ # Code borrowed from https://github.com/Pylons/webtest/blob/4b8a3ebf984185ff4fefb31b4d0cf82682e1fcf7/webtest/http.py#L93-L104
+ self.waitress.was_shutdown = True
+ while self.waitress._map:
+ triggers = list(self.waitress._map.values())
+ for trigger in triggers:
+ trigger.handle_close()
+ self.waitress.maintenance(0)
+ self.waitress.task_dispatcher.shutdown()
+ return True