mirror of
https://github.com/9001/copyparty.git
synced 2025-08-18 01:22:13 -06:00
signal handling was still busted
This commit is contained in:
parent
e648252479
commit
0d634345ac
|
@ -13,7 +13,7 @@ import threading
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import calendar
|
import calendar
|
||||||
|
|
||||||
from .__init__ import E, PY2, WINDOWS, MACOS, VT100, unicode
|
from .__init__ import E, PY2, WINDOWS, ANYWIN, MACOS, VT100, unicode
|
||||||
from .util import mp, start_log_thrs, start_stackmon, min_ex
|
from .util import mp, start_log_thrs, start_stackmon, min_ex
|
||||||
from .authsrv import AuthSrv
|
from .authsrv import AuthSrv
|
||||||
from .tcpsrv import TcpSrv
|
from .tcpsrv import TcpSrv
|
||||||
|
@ -139,20 +139,29 @@ class SvcHub(object):
|
||||||
thr.daemon = True
|
thr.daemon = True
|
||||||
thr.start()
|
thr.start()
|
||||||
|
|
||||||
thr = threading.Thread(target=self.stop_thr, name="svchub-sig")
|
|
||||||
thr.daemon = True
|
|
||||||
thr.start()
|
|
||||||
|
|
||||||
for sig in [signal.SIGINT, signal.SIGTERM]:
|
for sig in [signal.SIGINT, signal.SIGTERM]:
|
||||||
signal.signal(sig, self.signal_handler)
|
signal.signal(sig, self.signal_handler)
|
||||||
|
|
||||||
try:
|
# windows cannot ^c stop_cond,
|
||||||
while not self.stop_req:
|
# macos hangs after shutdown on sigterm with while-sleep,
|
||||||
time.sleep(9001)
|
# linux is fine with both,
|
||||||
except:
|
# never lucky
|
||||||
pass
|
if ANYWIN:
|
||||||
|
# msys-python probably fine but >msys-python
|
||||||
|
thr = threading.Thread(target=self.stop_thr, name="svchub-sig")
|
||||||
|
thr.daemon = True
|
||||||
|
thr.start()
|
||||||
|
|
||||||
self.shutdown()
|
ival = 1 if sys.gettrace() else 9001
|
||||||
|
try:
|
||||||
|
while not self.stop_req:
|
||||||
|
time.sleep(ival)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
self.shutdown()
|
||||||
|
else:
|
||||||
|
self.stop_thr()
|
||||||
|
|
||||||
def stop_thr(self):
|
def stop_thr(self):
|
||||||
while not self.stop_req:
|
while not self.stop_req:
|
||||||
|
@ -161,7 +170,7 @@ class SvcHub(object):
|
||||||
|
|
||||||
self.shutdown()
|
self.shutdown()
|
||||||
|
|
||||||
def signal_handler(self):
|
def signal_handler(self, sig, frame):
|
||||||
if self.stopping:
|
if self.stopping:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -175,6 +184,7 @@ class SvcHub(object):
|
||||||
|
|
||||||
self.stopping = True
|
self.stopping = True
|
||||||
self.stop_req = True
|
self.stop_req = True
|
||||||
|
ret = 1
|
||||||
try:
|
try:
|
||||||
with self.log_mutex:
|
with self.log_mutex:
|
||||||
print("OPYTHAT")
|
print("OPYTHAT")
|
||||||
|
@ -194,11 +204,14 @@ class SvcHub(object):
|
||||||
print("waiting for thumbsrv (10sec)...")
|
print("waiting for thumbsrv (10sec)...")
|
||||||
|
|
||||||
print("nailed it", end="")
|
print("nailed it", end="")
|
||||||
|
ret = 0
|
||||||
finally:
|
finally:
|
||||||
print("\033[0m")
|
print("\033[0m")
|
||||||
if self.logf:
|
if self.logf:
|
||||||
self.logf.close()
|
self.logf.close()
|
||||||
|
|
||||||
|
sys.exit(ret)
|
||||||
|
|
||||||
def _log_disabled(self, src, msg, c=0):
|
def _log_disabled(self, src, msg, c=0):
|
||||||
if not self.logf:
|
if not self.logf:
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue