aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/basethread.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2016-06-11 19:52:24 +1200
committerAldo Cortesi <aldo@nullcube.com>2016-06-11 19:52:24 +1200
commit09edbd9492e59c0c8dcae69b4b1f4b745867abe4 (patch)
treee9cf29c394334c02d908058c2c5e159715d3e3c3 /netlib/basethread.py
parent5b9f07c81c0dcc8c7b3d7afdeae8f6229ebf8622 (diff)
downloadmitmproxy-09edbd9492e59c0c8dcae69b4b1f4b745867abe4.tar.gz
mitmproxy-09edbd9492e59c0c8dcae69b4b1f4b745867abe4.tar.bz2
mitmproxy-09edbd9492e59c0c8dcae69b4b1f4b745867abe4.zip
Improve debugging of thread and other leaks
- Add basethread.BaseThread that all threads outside of test suites should use - Add a signal handler to mitmproxy, mitmdump and mitmweb that dumps resource information to screen when SIGUSR1 is received. - Improve thread naming throughout to make thread dumps understandable
Diffstat (limited to 'netlib/basethread.py')
-rw-r--r--netlib/basethread.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/netlib/basethread.py b/netlib/basethread.py
new file mode 100644
index 00000000..7963eb7e
--- /dev/null
+++ b/netlib/basethread.py
@@ -0,0 +1,14 @@
+import time
+import threading
+
+
+class BaseThread(threading.Thread):
+ def __init__(self, name, *args, **kwargs):
+ super(BaseThread, self).__init__(name=name, *args, **kwargs)
+ self._thread_started = time.time()
+
+ def _threadinfo(self):
+ return "%s - age: %is" % (
+ self.name,
+ int(time.time() - self._thread_started)
+ )