mirror of
https://github.com/9001/copyparty.git
synced 2025-08-18 01:22:13 -06:00
print() can deadlock 👁👄👁
This commit is contained in:
parent
0cfda684ce
commit
ea7c82c5e4
|
@ -150,6 +150,7 @@ class BrokerMp(object):
|
||||||
|
|
||||||
if msg != last:
|
if msg != last:
|
||||||
last = msg
|
last = msg
|
||||||
print(msg)
|
with self.hub.log_mutex:
|
||||||
|
print(msg)
|
||||||
|
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
|
@ -614,7 +614,7 @@ class HttpCli(object):
|
||||||
abspath = vn.canonical(rem)
|
abspath = vn.canonical(rem)
|
||||||
|
|
||||||
if not os.path.exists(fsenc(abspath)):
|
if not os.path.exists(fsenc(abspath)):
|
||||||
print(abspath)
|
# print(abspath)
|
||||||
raise Pebkac(404)
|
raise Pebkac(404)
|
||||||
|
|
||||||
if not os.path.isdir(fsenc(abspath)):
|
if not os.path.isdir(fsenc(abspath)):
|
||||||
|
|
|
@ -48,7 +48,7 @@ class HttpSrv(object):
|
||||||
return len(self.clients)
|
return len(self.clients)
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
print("ok bye")
|
self.log("ok bye")
|
||||||
|
|
||||||
def thr_client(self, sck, addr):
|
def thr_client(self, sck, addr):
|
||||||
"""thread managing one tcp client"""
|
"""thread managing one tcp client"""
|
||||||
|
@ -69,13 +69,20 @@ class HttpSrv(object):
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
self.log(str(addr), "-" * 7 + "C-done")
|
self.log(str(addr), "-" * 7 + "C-done")
|
||||||
sck.shutdown(socket.SHUT_RDWR)
|
try:
|
||||||
sck.close()
|
sck.shutdown(socket.SHUT_RDWR)
|
||||||
with self.mutex:
|
sck.close()
|
||||||
del self.clients[cli]
|
except (OSError, socket.error) as ex:
|
||||||
|
if ex.errno not in [107, 9]:
|
||||||
|
# 107 Transport endpoint not connected
|
||||||
|
# 9 Bad file descriptor
|
||||||
|
raise
|
||||||
|
finally:
|
||||||
|
with self.mutex:
|
||||||
|
del self.clients[cli]
|
||||||
|
|
||||||
if self.disconnect_func:
|
if self.disconnect_func:
|
||||||
self.disconnect_func(addr) # pylint: disable=not-callable
|
self.disconnect_func(addr) # pylint: disable=not-callable
|
||||||
|
|
||||||
def thr_workload(self):
|
def thr_workload(self):
|
||||||
"""indicates the python interpreter workload caused by this HttpSrv"""
|
"""indicates the python interpreter workload caused by this HttpSrv"""
|
||||||
|
|
|
@ -52,28 +52,31 @@ class SvcHub(object):
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
time.sleep(9001)
|
time.sleep(9001)
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("OPYTHAT")
|
with self.log_mutex:
|
||||||
|
print("OPYTHAT")
|
||||||
|
|
||||||
self.tcpsrv.shutdown()
|
self.tcpsrv.shutdown()
|
||||||
self.broker.shutdown()
|
self.broker.shutdown()
|
||||||
print("nailed it")
|
print("nailed it")
|
||||||
|
|
||||||
def log(self, src, msg):
|
def log(self, src, msg):
|
||||||
"""handles logging from all components"""
|
"""handles logging from all components"""
|
||||||
now = time.time()
|
|
||||||
if now >= self.next_day:
|
|
||||||
dt = datetime.utcfromtimestamp(now)
|
|
||||||
print("\033[36m{}\033[0m".format(dt.strftime("%Y-%m-%d")))
|
|
||||||
|
|
||||||
# unix timestamp of next 00:00:00 (leap-seconds safe)
|
|
||||||
day_now = dt.day
|
|
||||||
while dt.day == day_now:
|
|
||||||
dt += timedelta(hours=12)
|
|
||||||
|
|
||||||
dt = dt.replace(hour=0, minute=0, second=0)
|
|
||||||
self.next_day = calendar.timegm(dt.utctimetuple())
|
|
||||||
|
|
||||||
with self.log_mutex:
|
with self.log_mutex:
|
||||||
|
now = time.time()
|
||||||
|
if now >= self.next_day:
|
||||||
|
dt = datetime.utcfromtimestamp(now)
|
||||||
|
print("\033[36m{}\033[0m".format(dt.strftime("%Y-%m-%d")))
|
||||||
|
|
||||||
|
# unix timestamp of next 00:00:00 (leap-seconds safe)
|
||||||
|
day_now = dt.day
|
||||||
|
while dt.day == day_now:
|
||||||
|
dt += timedelta(hours=12)
|
||||||
|
|
||||||
|
dt = dt.replace(hour=0, minute=0, second=0)
|
||||||
|
self.next_day = calendar.timegm(dt.utctimetuple())
|
||||||
|
|
||||||
ts = datetime.utcfromtimestamp(now).strftime("%H:%M:%S")
|
ts = datetime.utcfromtimestamp(now).strftime("%H:%M:%S")
|
||||||
print("\033[36m{} \033[33m{:21} \033[0m{}".format(ts, src, msg))
|
print("\033[36m{} \033[33m{:21} \033[0m{}".format(ts, src, msg))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue