diff --git a/copyparty/broker_mp.py b/copyparty/broker_mp.py index c0bbd8b1..52cc9f96 100644 --- a/copyparty/broker_mp.py +++ b/copyparty/broker_mp.py @@ -44,7 +44,9 @@ class BrokerMp(object): proc.clients = {} proc.workload = 0 - thr = threading.Thread(target=self.collector, args=(proc,)) + thr = threading.Thread( + target=self.collector, args=(proc,), name="mp-collector" + ) thr.daemon = True thr.start() @@ -52,14 +54,19 @@ class BrokerMp(object): proc.start() if not self.args.q: - thr = threading.Thread(target=self.debug_load_balancer) + thr = threading.Thread( + target=self.debug_load_balancer, name="mp-dbg-loadbalancer" + ) thr.daemon = True thr.start() def shutdown(self): self.log("broker", "shutting down") - for proc in self.procs: - thr = threading.Thread(target=proc.q_pend.put([0, "shutdown", []])) + for n, proc in enumerate(self.procs): + thr = threading.Thread( + target=proc.q_pend.put([0, "shutdown", []]), + name="mp-shutdown-{}-{}".format(n, len(self.procs)), + ) thr.start() with self.mutex: diff --git a/copyparty/broker_mpw.py b/copyparty/broker_mpw.py index fdfbbe43..6dd03627 100644 --- a/copyparty/broker_mpw.py +++ b/copyparty/broker_mpw.py @@ -27,7 +27,7 @@ class MpWorker(object): self.retpend = {} self.retpend_mutex = threading.Lock() self.mutex = threading.Lock() - self.workload_thr_active = False + self.workload_thr_alive = False # we inherited signal_handler from parent, # replace it with something harmless @@ -40,7 +40,7 @@ class MpWorker(object): # on winxp and some other platforms, # use thr.join() to block all signals - thr = threading.Thread(target=self.main) + thr = threading.Thread(target=self.main, name="mpw-main") thr.daemon = True thr.start() thr.join() @@ -79,9 +79,11 @@ class MpWorker(object): self.httpsrv.accept(sck, addr) with self.mutex: - if not self.workload_thr_active: + if not self.workload_thr_alive: self.workload_thr_alive = True - thr = threading.Thread(target=self.thr_workload) + thr = threading.Thread( + target=self.thr_workload, name="mpw-workload" + ) thr.daemon = True thr.start() diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 5bd64b4f..dd80a7b6 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -1378,15 +1378,31 @@ class HttpCli(object): if self.args.no_stack: raise Pebkac(403, "disabled by argv") - ret = [] + threads = {} names = dict([(t.ident, t.name) for t in threading.enumerate()]) for tid, stack in sys._current_frames().items(): - ret.append("\n\n# {} ({:x})".format(names.get(tid), tid)) + name = "{} ({:x})".format(names.get(tid), tid) + threads[name] = stack + + rret = [] + bret = [] + for name, stack in sorted(threads.items()): + ret = ["\n\n# {}".format(name)] + pad = None for fn, lno, name, line in traceback.extract_stack(stack): + fn = os.sep.join(fn.split(os.sep)[-3:]) ret.append('File: "{}", line {}, in {}'.format(fn, lno, name)) if line: ret.append(" " + str(line.strip())) + if "self.not_empty.wait()" in line: + pad = " " * 4 + if pad: + bret += [ret[0]] + [pad + x for x in ret[1:]] + else: + rret += ret + + ret = rret + bret ret = ("
" + "\n".join(ret)).encode("utf-8")
self.reply(ret)
diff --git a/copyparty/httpsrv.py b/copyparty/httpsrv.py
index 356d9c58..6f3375fd 100644
--- a/copyparty/httpsrv.py
+++ b/copyparty/httpsrv.py
@@ -67,7 +67,11 @@ class HttpSrv(object):
if self.args.log_conn:
self.log("%s %s" % addr, "|%sC-cthr" % ("-" * 5,), c="1;30")
- thr = threading.Thread(target=self.thr_client, args=(sck, addr))
+ thr = threading.Thread(
+ target=self.thr_client,
+ args=(sck, addr),
+ name="httpsrv-{}-{}".format(addr[0].split(".", 2)[-1][-6:], addr[1]),
+ )
thr.daemon = True
thr.start()
@@ -90,7 +94,9 @@ class HttpSrv(object):
self.workload += 50
if not self.workload_thr_alive:
self.workload_thr_alive = True
- thr = threading.Thread(target=self.thr_workload)
+ thr = threading.Thread(
+ target=self.thr_workload, name="httpsrv-workload"
+ )
thr.daemon = True
thr.start()
diff --git a/copyparty/star.py b/copyparty/star.py
index 621fddd9..e6d3bb73 100644
--- a/copyparty/star.py
+++ b/copyparty/star.py
@@ -42,7 +42,7 @@ class StreamTar(object):
fmt = tarfile.GNU_FORMAT
self.tar = tarfile.open(fileobj=self.qfile, mode="w|", format=fmt)
- w = threading.Thread(target=self._gen)
+ w = threading.Thread(target=self._gen, name="star-gen")
w.daemon = True
w.start()
diff --git a/copyparty/svchub.py b/copyparty/svchub.py
index 409bbf13..3e123efc 100644
--- a/copyparty/svchub.py
+++ b/copyparty/svchub.py
@@ -71,7 +71,7 @@ class SvcHub(object):
self.broker = Broker(self)
def run(self):
- thr = threading.Thread(target=self.tcpsrv.run)
+ thr = threading.Thread(target=self.tcpsrv.run, name="svchub-main")
thr.daemon = True
thr.start()
diff --git a/copyparty/th_srv.py b/copyparty/th_srv.py
index 75622a99..27a49e82 100644
--- a/copyparty/th_srv.py
+++ b/copyparty/th_srv.py
@@ -114,8 +114,10 @@ class ThumbSrv(object):
self.stopping = False
self.nthr = os.cpu_count() if hasattr(os, "cpu_count") else 4
self.q = Queue(self.nthr * 4)
- for _ in range(self.nthr):
- t = threading.Thread(target=self.worker)
+ for n in range(self.nthr):
+ t = threading.Thread(
+ target=self.worker, name="thumb-{}-{}".format(n, self.nthr)
+ )
t.daemon = True
t.start()
@@ -131,7 +133,7 @@ class ThumbSrv(object):
msg += ", ".join(missing)
self.log(msg, c=3)
- t = threading.Thread(target=self.cleaner)
+ t = threading.Thread(target=self.cleaner, name="thumb-cleaner")
t.daemon = True
t.start()
diff --git a/copyparty/u2idx.py b/copyparty/u2idx.py
index a642f9bd..1e2c3612 100644
--- a/copyparty/u2idx.py
+++ b/copyparty/u2idx.py
@@ -192,6 +192,7 @@ class U2idx(object):
self.active_id,
done_flag,
),
+ name="u2idx-terminator",
)
thr.daemon = True
thr.start()
diff --git a/copyparty/up2k.py b/copyparty/up2k.py
index 42ba849f..21510441 100644
--- a/copyparty/up2k.py
+++ b/copyparty/up2k.py
@@ -83,7 +83,7 @@ class Up2k(object):
if ANYWIN:
# usually fails to set lastmod too quickly
self.lastmod_q = Queue()
- thr = threading.Thread(target=self._lastmodder)
+ thr = threading.Thread(target=self._lastmodder, name="up2k-lastmod")
thr.daemon = True
thr.start()
@@ -96,7 +96,9 @@ class Up2k(object):
if self.args.no_fastboot:
self.deferred_init(all_vols)
else:
- t = threading.Thread(target=self.deferred_init, args=(all_vols,))
+ t = threading.Thread(
+ target=self.deferred_init, args=(all_vols,), name="up2k-deferred-init"
+ )
t.daemon = True
t.start()
@@ -104,20 +106,20 @@ class Up2k(object):
have_e2d = self.init_indexes(all_vols)
if have_e2d:
- thr = threading.Thread(target=self._snapshot)
+ thr = threading.Thread(target=self._snapshot, name="up2k-snapshot")
thr.daemon = True
thr.start()
- thr = threading.Thread(target=self._hasher)
+ thr = threading.Thread(target=self._hasher, name="up2k-hasher")
thr.daemon = True
thr.start()
if self.mtag:
- thr = threading.Thread(target=self._tagger)
+ thr = threading.Thread(target=self._tagger, name="up2k-tagger")
thr.daemon = True
thr.start()
- thr = threading.Thread(target=self._run_all_mtp)
+ thr = threading.Thread(target=self._run_all_mtp, name="up2k-mtp-init")
thr.daemon = True
thr.start()
@@ -132,7 +134,11 @@ class Up2k(object):
return "cannot initiate; scan is already in progress"
args = (all_vols, scan_vols)
- t = threading.Thread(target=self.init_indexes, args=args)
+ t = threading.Thread(
+ target=self.init_indexes,
+ args=args,
+ name="up2k-rescan-{}".format(scan_vols[0]),
+ )
t.daemon = True
t.start()
return None
@@ -273,7 +279,7 @@ class Up2k(object):
if self.mtag:
m = "online (running mtp)"
if scan_vols:
- thr = threading.Thread(target=self._run_all_mtp)
+ thr = threading.Thread(target=self._run_all_mtp, name="up2k-mtp-scan")
thr.daemon = True
else:
del self.pp
@@ -758,7 +764,9 @@ class Up2k(object):
mpool = Queue(nw)
for _ in range(nw):
- thr = threading.Thread(target=self._tag_thr, args=(mpool,))
+ thr = threading.Thread(
+ target=self._tag_thr, args=(mpool,), name="up2k-mpool"
+ )
thr.daemon = True
thr.start()
diff --git a/copyparty/util.py b/copyparty/util.py
index 17b91203..9b714c12 100644
--- a/copyparty/util.py
+++ b/copyparty/util.py
@@ -193,7 +193,7 @@ class ProgressPrinter(threading.Thread):
"""
def __init__(self):
- threading.Thread.__init__(self)
+ threading.Thread.__init__(self, name="pp")
self.daemon = True
self.msg = None
self.end = False