print() can deadlock 👁👄👁

This commit is contained in:
ed 2019-07-03 22:25:51 +00:00
parent 0cfda684ce
commit ea7c82c5e4
4 changed files with 34 additions and 23 deletions

View file

@ -150,6 +150,7 @@ class BrokerMp(object):
if msg != last:
last = msg
with self.hub.log_mutex:
print(msg)
time.sleep(0.1)

View file

@ -614,7 +614,7 @@ class HttpCli(object):
abspath = vn.canonical(rem)
if not os.path.exists(fsenc(abspath)):
print(abspath)
# print(abspath)
raise Pebkac(404)
if not os.path.isdir(fsenc(abspath)):

View file

@ -48,7 +48,7 @@ class HttpSrv(object):
return len(self.clients)
def shutdown(self):
print("ok bye")
self.log("ok bye")
def thr_client(self, sck, addr):
"""thread managing one tcp client"""
@ -69,8 +69,15 @@ class HttpSrv(object):
finally:
self.log(str(addr), "-" * 7 + "C-done")
try:
sck.shutdown(socket.SHUT_RDWR)
sck.close()
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]

View file

@ -52,14 +52,18 @@ class SvcHub(object):
try:
while True:
time.sleep(9001)
except KeyboardInterrupt:
with self.log_mutex:
print("OPYTHAT")
self.tcpsrv.shutdown()
self.broker.shutdown()
print("nailed it")
def log(self, src, msg):
"""handles logging from all components"""
with self.log_mutex:
now = time.time()
if now >= self.next_day:
dt = datetime.utcfromtimestamp(now)
@ -73,7 +77,6 @@ class SvcHub(object):
dt = dt.replace(hour=0, minute=0, second=0)
self.next_day = calendar.timegm(dt.utctimetuple())
with self.log_mutex:
ts = datetime.utcfromtimestamp(now).strftime("%H:%M:%S")
print("\033[36m{} \033[33m{:21} \033[0m{}".format(ts, src, msg))