aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2011-03-15 17:21:35 +1300
committerAldo Cortesi <aldo@nullcube.com>2011-03-15 17:21:35 +1300
commit6d5c32ad4b6078a72b73b695981faec36ef917c0 (patch)
treecc19a507899bcd25905a325d9a6f08e47130291c /libmproxy
parentfb28e71f0b1beb68723a2d89e008793325cee715 (diff)
downloadmitmproxy-6d5c32ad4b6078a72b73b695981faec36ef917c0.tar.gz
mitmproxy-6d5c32ad4b6078a72b73b695981faec36ef917c0.tar.bz2
mitmproxy-6d5c32ad4b6078a72b73b695981faec36ef917c0.zip
Fix hang on shutdown.
Diffstat (limited to 'libmproxy')
-rw-r--r--libmproxy/console.py2
-rw-r--r--libmproxy/controller.py19
2 files changed, 13 insertions, 8 deletions
diff --git a/libmproxy/console.py b/libmproxy/console.py
index 9dd80c7e..d36d87da 100644
--- a/libmproxy/console.py
+++ b/libmproxy/console.py
@@ -1277,7 +1277,7 @@ class ConsoleMaster(flow.FlowMaster):
slave = controller.Slave(q, self.server)
slave.start()
try:
- while not self._shutdown:
+ while not controller.exit:
self.statusbar.redraw()
size = self.drawscreen()
self.tick(q)
diff --git a/libmproxy/controller.py b/libmproxy/controller.py
index 82e934c4..52b6ac6b 100644
--- a/libmproxy/controller.py
+++ b/libmproxy/controller.py
@@ -16,6 +16,8 @@
import sys
import Queue, threading
+exit = False
+
#begin nocover
class Msg:
@@ -34,7 +36,12 @@ class Msg:
self.acked = False
try:
masterq.put(self, timeout=3)
- return self.q.get()
+ while not exit:
+ try:
+ g = self.q.get(timeout=0.5)
+ except Queue.Empty:
+ continue
+ return g
except (Queue.Empty, Queue.Full):
return None
@@ -52,7 +59,6 @@ class Slave(threading.Thread):
class Master:
def __init__(self, server):
self.server = server
- self._shutdown = False
self.masterq = None
def tick(self, q):
@@ -73,7 +79,7 @@ class Master:
self.masterq = q
slave = Slave(q, self.server)
slave.start()
- while not self._shutdown:
+ while not exit:
self.tick(q)
self.shutdown()
@@ -86,9 +92,8 @@ class Master:
msg.ack()
def shutdown(self):
- if not self._shutdown:
- self._shutdown = True
+ global exit
+ if not exit:
+ exit = True
if self.server:
self.server.shutdown()
-
-