mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 17:12:13 -06:00
add thread names
This commit is contained in:
parent
4dd5d4e1b7
commit
9d729d3d1a
|
@ -44,7 +44,9 @@ class BrokerMp(object):
|
||||||
proc.clients = {}
|
proc.clients = {}
|
||||||
proc.workload = 0
|
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.daemon = True
|
||||||
thr.start()
|
thr.start()
|
||||||
|
|
||||||
|
@ -52,14 +54,19 @@ class BrokerMp(object):
|
||||||
proc.start()
|
proc.start()
|
||||||
|
|
||||||
if not self.args.q:
|
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.daemon = True
|
||||||
thr.start()
|
thr.start()
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
self.log("broker", "shutting down")
|
self.log("broker", "shutting down")
|
||||||
for proc in self.procs:
|
for n, proc in enumerate(self.procs):
|
||||||
thr = threading.Thread(target=proc.q_pend.put([0, "shutdown", []]))
|
thr = threading.Thread(
|
||||||
|
target=proc.q_pend.put([0, "shutdown", []]),
|
||||||
|
name="mp-shutdown-{}-{}".format(n, len(self.procs)),
|
||||||
|
)
|
||||||
thr.start()
|
thr.start()
|
||||||
|
|
||||||
with self.mutex:
|
with self.mutex:
|
||||||
|
|
|
@ -27,7 +27,7 @@ class MpWorker(object):
|
||||||
self.retpend = {}
|
self.retpend = {}
|
||||||
self.retpend_mutex = threading.Lock()
|
self.retpend_mutex = threading.Lock()
|
||||||
self.mutex = threading.Lock()
|
self.mutex = threading.Lock()
|
||||||
self.workload_thr_active = False
|
self.workload_thr_alive = False
|
||||||
|
|
||||||
# we inherited signal_handler from parent,
|
# we inherited signal_handler from parent,
|
||||||
# replace it with something harmless
|
# replace it with something harmless
|
||||||
|
@ -40,7 +40,7 @@ class MpWorker(object):
|
||||||
|
|
||||||
# on winxp and some other platforms,
|
# on winxp and some other platforms,
|
||||||
# use thr.join() to block all signals
|
# 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.daemon = True
|
||||||
thr.start()
|
thr.start()
|
||||||
thr.join()
|
thr.join()
|
||||||
|
@ -79,9 +79,11 @@ class MpWorker(object):
|
||||||
self.httpsrv.accept(sck, addr)
|
self.httpsrv.accept(sck, addr)
|
||||||
|
|
||||||
with self.mutex:
|
with self.mutex:
|
||||||
if not self.workload_thr_active:
|
if not self.workload_thr_alive:
|
||||||
self.workload_thr_alive = True
|
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.daemon = True
|
||||||
thr.start()
|
thr.start()
|
||||||
|
|
||||||
|
|
|
@ -1378,15 +1378,31 @@ class HttpCli(object):
|
||||||
if self.args.no_stack:
|
if self.args.no_stack:
|
||||||
raise Pebkac(403, "disabled by argv")
|
raise Pebkac(403, "disabled by argv")
|
||||||
|
|
||||||
ret = []
|
threads = {}
|
||||||
names = dict([(t.ident, t.name) for t in threading.enumerate()])
|
names = dict([(t.ident, t.name) for t in threading.enumerate()])
|
||||||
for tid, stack in sys._current_frames().items():
|
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):
|
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))
|
ret.append('File: "{}", line {}, in {}'.format(fn, lno, name))
|
||||||
if line:
|
if line:
|
||||||
ret.append(" " + str(line.strip()))
|
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 = ("<pre>" + "\n".join(ret)).encode("utf-8")
|
ret = ("<pre>" + "\n".join(ret)).encode("utf-8")
|
||||||
self.reply(ret)
|
self.reply(ret)
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,11 @@ class HttpSrv(object):
|
||||||
if self.args.log_conn:
|
if self.args.log_conn:
|
||||||
self.log("%s %s" % addr, "|%sC-cthr" % ("-" * 5,), c="1;30")
|
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.daemon = True
|
||||||
thr.start()
|
thr.start()
|
||||||
|
|
||||||
|
@ -90,7 +94,9 @@ class HttpSrv(object):
|
||||||
self.workload += 50
|
self.workload += 50
|
||||||
if not self.workload_thr_alive:
|
if not self.workload_thr_alive:
|
||||||
self.workload_thr_alive = True
|
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.daemon = True
|
||||||
thr.start()
|
thr.start()
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ class StreamTar(object):
|
||||||
fmt = tarfile.GNU_FORMAT
|
fmt = tarfile.GNU_FORMAT
|
||||||
self.tar = tarfile.open(fileobj=self.qfile, mode="w|", format=fmt)
|
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.daemon = True
|
||||||
w.start()
|
w.start()
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ class SvcHub(object):
|
||||||
self.broker = Broker(self)
|
self.broker = Broker(self)
|
||||||
|
|
||||||
def run(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.daemon = True
|
||||||
thr.start()
|
thr.start()
|
||||||
|
|
||||||
|
|
|
@ -114,8 +114,10 @@ class ThumbSrv(object):
|
||||||
self.stopping = False
|
self.stopping = False
|
||||||
self.nthr = os.cpu_count() if hasattr(os, "cpu_count") else 4
|
self.nthr = os.cpu_count() if hasattr(os, "cpu_count") else 4
|
||||||
self.q = Queue(self.nthr * 4)
|
self.q = Queue(self.nthr * 4)
|
||||||
for _ in range(self.nthr):
|
for n in range(self.nthr):
|
||||||
t = threading.Thread(target=self.worker)
|
t = threading.Thread(
|
||||||
|
target=self.worker, name="thumb-{}-{}".format(n, self.nthr)
|
||||||
|
)
|
||||||
t.daemon = True
|
t.daemon = True
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
|
@ -131,7 +133,7 @@ class ThumbSrv(object):
|
||||||
msg += ", ".join(missing)
|
msg += ", ".join(missing)
|
||||||
self.log(msg, c=3)
|
self.log(msg, c=3)
|
||||||
|
|
||||||
t = threading.Thread(target=self.cleaner)
|
t = threading.Thread(target=self.cleaner, name="thumb-cleaner")
|
||||||
t.daemon = True
|
t.daemon = True
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
|
|
|
@ -192,6 +192,7 @@ class U2idx(object):
|
||||||
self.active_id,
|
self.active_id,
|
||||||
done_flag,
|
done_flag,
|
||||||
),
|
),
|
||||||
|
name="u2idx-terminator",
|
||||||
)
|
)
|
||||||
thr.daemon = True
|
thr.daemon = True
|
||||||
thr.start()
|
thr.start()
|
||||||
|
|
|
@ -83,7 +83,7 @@ class Up2k(object):
|
||||||
if ANYWIN:
|
if ANYWIN:
|
||||||
# usually fails to set lastmod too quickly
|
# usually fails to set lastmod too quickly
|
||||||
self.lastmod_q = Queue()
|
self.lastmod_q = Queue()
|
||||||
thr = threading.Thread(target=self._lastmodder)
|
thr = threading.Thread(target=self._lastmodder, name="up2k-lastmod")
|
||||||
thr.daemon = True
|
thr.daemon = True
|
||||||
thr.start()
|
thr.start()
|
||||||
|
|
||||||
|
@ -96,7 +96,9 @@ class Up2k(object):
|
||||||
if self.args.no_fastboot:
|
if self.args.no_fastboot:
|
||||||
self.deferred_init(all_vols)
|
self.deferred_init(all_vols)
|
||||||
else:
|
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.daemon = True
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
|
@ -104,20 +106,20 @@ class Up2k(object):
|
||||||
have_e2d = self.init_indexes(all_vols)
|
have_e2d = self.init_indexes(all_vols)
|
||||||
|
|
||||||
if have_e2d:
|
if have_e2d:
|
||||||
thr = threading.Thread(target=self._snapshot)
|
thr = threading.Thread(target=self._snapshot, name="up2k-snapshot")
|
||||||
thr.daemon = True
|
thr.daemon = True
|
||||||
thr.start()
|
thr.start()
|
||||||
|
|
||||||
thr = threading.Thread(target=self._hasher)
|
thr = threading.Thread(target=self._hasher, name="up2k-hasher")
|
||||||
thr.daemon = True
|
thr.daemon = True
|
||||||
thr.start()
|
thr.start()
|
||||||
|
|
||||||
if self.mtag:
|
if self.mtag:
|
||||||
thr = threading.Thread(target=self._tagger)
|
thr = threading.Thread(target=self._tagger, name="up2k-tagger")
|
||||||
thr.daemon = True
|
thr.daemon = True
|
||||||
thr.start()
|
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.daemon = True
|
||||||
thr.start()
|
thr.start()
|
||||||
|
|
||||||
|
@ -132,7 +134,11 @@ class Up2k(object):
|
||||||
return "cannot initiate; scan is already in progress"
|
return "cannot initiate; scan is already in progress"
|
||||||
|
|
||||||
args = (all_vols, scan_vols)
|
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.daemon = True
|
||||||
t.start()
|
t.start()
|
||||||
return None
|
return None
|
||||||
|
@ -273,7 +279,7 @@ class Up2k(object):
|
||||||
if self.mtag:
|
if self.mtag:
|
||||||
m = "online (running mtp)"
|
m = "online (running mtp)"
|
||||||
if scan_vols:
|
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
|
thr.daemon = True
|
||||||
else:
|
else:
|
||||||
del self.pp
|
del self.pp
|
||||||
|
@ -758,7 +764,9 @@ class Up2k(object):
|
||||||
|
|
||||||
mpool = Queue(nw)
|
mpool = Queue(nw)
|
||||||
for _ in range(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.daemon = True
|
||||||
thr.start()
|
thr.start()
|
||||||
|
|
||||||
|
|
|
@ -193,7 +193,7 @@ class ProgressPrinter(threading.Thread):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self, name="pp")
|
||||||
self.daemon = True
|
self.daemon = True
|
||||||
self.msg = None
|
self.msg = None
|
||||||
self.end = False
|
self.end = False
|
||||||
|
|
Loading…
Reference in a new issue