Parallel Shutdown of file_server and ui_server

Make Parallel Shutdown of file_server and ui_server at Shutdown of ZeroNet
This commit is contained in:
canewsin 2021-12-22 15:09:52 +05:30
parent f79aca1dad
commit 7dbf8da8cb

View file

@ -10,21 +10,33 @@ from Config import config
from . import Debug
last_error = None
thread_shutdown = None
def shutdown(reason="Unknown"):
logging.info("Shutting down (reason: %s)..." % reason)
def shutdownThread():
import main
if "file_server" in dir(main):
try:
gevent.spawn(main.file_server.stop)
if "file_server" in dir(main):
thread = gevent.spawn(main.file_server.stop)
thread.join(timeout=60)
if "ui_server" in dir(main):
gevent.spawn(main.ui_server.stop)
thread = gevent.spawn(main.ui_server.stop)
thread.join(timeout=10)
except Exception as err:
print("Proper shutdown error: %s" % err)
print("Error in shutdown thread: %s" % err)
sys.exit(0)
else:
sys.exit(0)
def shutdown(reason="Unknown"):
global thread_shutdown
logging.info("Shutting down (reason: %s)..." % reason)
try:
if not thread_shutdown:
thread_shutdown = gevent.spawn(shutdownThread)
except Exception as err:
print("Proper shutdown error: %s" % err)
sys.exit(0)
# Store last error, ignore notify, allow manual error logging
def handleError(*args, **kwargs):
global last_error