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:
parent
f79aca1dad
commit
7dbf8da8cb
1 changed files with 22 additions and 10 deletions
|
@ -10,19 +10,31 @@ from Config import config
|
||||||
from . import Debug
|
from . import Debug
|
||||||
|
|
||||||
last_error = None
|
last_error = None
|
||||||
|
thread_shutdown = None
|
||||||
|
|
||||||
|
def shutdownThread():
|
||||||
|
import main
|
||||||
|
try:
|
||||||
|
if "file_server" in dir(main):
|
||||||
|
thread = gevent.spawn(main.file_server.stop)
|
||||||
|
thread.join(timeout=60)
|
||||||
|
if "ui_server" in dir(main):
|
||||||
|
thread = gevent.spawn(main.ui_server.stop)
|
||||||
|
thread.join(timeout=10)
|
||||||
|
except Exception as err:
|
||||||
|
print("Error in shutdown thread: %s" % err)
|
||||||
|
sys.exit(0)
|
||||||
|
else:
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
def shutdown(reason="Unknown"):
|
def shutdown(reason="Unknown"):
|
||||||
|
global thread_shutdown
|
||||||
logging.info("Shutting down (reason: %s)..." % reason)
|
logging.info("Shutting down (reason: %s)..." % reason)
|
||||||
import main
|
try:
|
||||||
if "file_server" in dir(main):
|
if not thread_shutdown:
|
||||||
try:
|
thread_shutdown = gevent.spawn(shutdownThread)
|
||||||
gevent.spawn(main.file_server.stop)
|
except Exception as err:
|
||||||
if "ui_server" in dir(main):
|
print("Proper shutdown error: %s" % err)
|
||||||
gevent.spawn(main.ui_server.stop)
|
|
||||||
except Exception as err:
|
|
||||||
print("Proper shutdown error: %s" % err)
|
|
||||||
sys.exit(0)
|
|
||||||
else:
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
# Store last error, ignore notify, allow manual error logging
|
# Store last error, ignore notify, allow manual error logging
|
||||||
|
|
Loading…
Reference in a new issue