aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/controller.py
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2014-07-03 02:20:38 +0200
committerMaximilian Hils <git@maximilianhils.com>2014-07-03 02:20:38 +0200
commitdf11595fad287a8ffdecd2ccc18b27478925c5b4 (patch)
tree9460f817c84425ce313882e4fe8595e0a0c54e35 /libmproxy/controller.py
parentc039e4a2e322ee4e0a173f164be598dc630d3579 (diff)
parentb7c1d057828054a7e8d5f9ccf2c3c93ca8888ed3 (diff)
downloadmitmproxy-df11595fad287a8ffdecd2ccc18b27478925c5b4.tar.gz
mitmproxy-df11595fad287a8ffdecd2ccc18b27478925c5b4.tar.bz2
mitmproxy-df11595fad287a8ffdecd2ccc18b27478925c5b4.zip
Merge pull request #286 from m0sth8/remove_global_should_exit
Remove global should_exit and fix tests
Diffstat (limited to 'libmproxy/controller.py')
-rw-r--r--libmproxy/controller.py21
1 files changed, 9 insertions, 12 deletions
diff --git a/libmproxy/controller.py b/libmproxy/controller.py
index c4a60854..63e44241 100644
--- a/libmproxy/controller.py
+++ b/libmproxy/controller.py
@@ -1,9 +1,6 @@
from __future__ import absolute_import
import Queue, threading
-should_exit = False
-
-
class DummyReply:
"""
A reply object that does nothing. Useful when we need an object to seem
@@ -37,8 +34,9 @@ class Reply:
class Channel:
- def __init__(self, q):
+ def __init__(self, q, should_exit):
self.q = q
+ self.should_exit = should_exit
def ask(self, mtype, m):
"""
@@ -47,7 +45,7 @@ class Channel:
"""
m.reply = Reply(m)
self.q.put((mtype, m))
- while not should_exit:
+ while not self.should_exit.is_set():
try:
# The timeout is here so we can handle a should_exit event.
g = m.reply.q.get(timeout=0.5)
@@ -89,6 +87,7 @@ class Master:
"""
self.server = server
self.masterq = Queue.Queue()
+ self.should_exit = threading.Event()
def tick(self, q):
changed = False
@@ -107,10 +106,9 @@ class Master:
return changed
def run(self):
- global should_exit
- should_exit = False
- self.server.start_slave(Slave, Channel(self.masterq))
- while not should_exit:
+ self.should_exit.clear()
+ self.server.start_slave(Slave, Channel(self.masterq, self.should_exit))
+ while not self.should_exit.is_set():
self.tick(self.masterq)
self.shutdown()
@@ -123,8 +121,7 @@ class Master:
obj.reply()
def shutdown(self):
- global should_exit
- if not should_exit:
- should_exit = True
+ if not self.should_exit.is_set():
+ self.should_exit.set()
if self.server:
self.server.shutdown()