diff --git a/copyparty/broker_mp.py b/copyparty/broker_mp.py index f4d15050..c2347093 100644 --- a/copyparty/broker_mp.py +++ b/copyparty/broker_mp.py @@ -150,6 +150,7 @@ class BrokerMp(object): if msg != last: last = msg - print(msg) + with self.hub.log_mutex: + print(msg) time.sleep(0.1) diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 9594ed15..4cff3bf8 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -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)): diff --git a/copyparty/httpsrv.py b/copyparty/httpsrv.py index caf548f6..447efc3c 100644 --- a/copyparty/httpsrv.py +++ b/copyparty/httpsrv.py @@ -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,13 +69,20 @@ class HttpSrv(object): finally: self.log(str(addr), "-" * 7 + "C-done") - sck.shutdown(socket.SHUT_RDWR) - sck.close() - with self.mutex: - del self.clients[cli] + 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] - if self.disconnect_func: - self.disconnect_func(addr) # pylint: disable=not-callable + if self.disconnect_func: + self.disconnect_func(addr) # pylint: disable=not-callable def thr_workload(self): """indicates the python interpreter workload caused by this HttpSrv""" diff --git a/copyparty/svchub.py b/copyparty/svchub.py index c2a83b49..430f4a4a 100644 --- a/copyparty/svchub.py +++ b/copyparty/svchub.py @@ -52,28 +52,31 @@ class SvcHub(object): try: while True: time.sleep(9001) + except KeyboardInterrupt: - print("OPYTHAT") + 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""" - 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: + 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") print("\033[36m{} \033[33m{:21} \033[0m{}".format(ts, src, msg))