aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libmproxy/console.py2
-rw-r--r--libmproxy/controller.py19
-rw-r--r--test/test_flow.py4
-rw-r--r--test/tutils.py1
4 files changed, 16 insertions, 10 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()
-
-
diff --git a/test/test_flow.py b/test/test_flow.py
index 91e3f5f4..a3fa48d7 100644
--- a/test/test_flow.py
+++ b/test/test_flow.py
@@ -1,6 +1,6 @@
import Queue
from cStringIO import StringIO
-from libmproxy import console, proxy, filt, flow
+from libmproxy import console, proxy, filt, flow, controller
import tutils
import libpry
@@ -442,7 +442,7 @@ class uFlowMaster(libpry.AutoTree):
assert fm.do_server_playback(tutils.tflow())
q = Queue.Queue()
fm.tick(q)
- assert fm._shutdown
+ assert controller.exit
def test_stickycookie(self):
s = flow.State()
diff --git a/test/tutils.py b/test/tutils.py
index ec2c71a8..ae9dea27 100644
--- a/test/tutils.py
+++ b/test/tutils.py
@@ -59,6 +59,7 @@ class TestMaster(controller.Master):
class ProxyThread(threading.Thread):
def __init__(self, port, testq):
self.tmaster = TestMaster(port, testq)
+ controller.exit = False
threading.Thread.__init__(self)
def run(self):