aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/controller.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2016-07-14 17:22:22 +1200
committerAldo Cortesi <aldo@nullcube.com>2016-07-14 19:54:15 +1200
commit5b2d1c044a0683444f117d8085e29bb613dbbf9d (patch)
tree01b9d403b298531233a9ef84948deccdb10ed8d1 /mitmproxy/controller.py
parentdeffed2196a8d595624998b9fcc8fa4016b41808 (diff)
downloadmitmproxy-5b2d1c044a0683444f117d8085e29bb613dbbf9d.tar.gz
mitmproxy-5b2d1c044a0683444f117d8085e29bb613dbbf9d.tar.bz2
mitmproxy-5b2d1c044a0683444f117d8085e29bb613dbbf9d.zip
Tighten the tick loop
In the past, we consumed from the event queue until we were idle for a certain amount of time (0.1s). This would cause hangs in interactive tools when there was a stream of events, hurting responsiveness. We now wait for a maximum of 0.1s before triggering the tick loop, will be able to reduce this further down the track.
Diffstat (limited to 'mitmproxy/controller.py')
-rw-r--r--mitmproxy/controller.py31
1 files changed, 14 insertions, 17 deletions
diff --git a/mitmproxy/controller.py b/mitmproxy/controller.py
index bffef58a..72f8e001 100644
--- a/mitmproxy/controller.py
+++ b/mitmproxy/controller.py
@@ -110,24 +110,21 @@ class Master(object):
def tick(self, timeout):
changed = False
try:
- # This endless loop runs until the 'Queue.Empty'
- # exception is thrown.
- while True:
- mtype, obj = self.event_queue.get(timeout=timeout)
- if mtype not in Events:
- raise exceptions.ControlException("Unknown event %s" % repr(mtype))
- handle_func = getattr(self, mtype)
- if not callable(handle_func):
- raise exceptions.ControlException("Handler %s not callable" % mtype)
- if not handle_func.__dict__.get("__handler"):
- raise exceptions.ControlException(
- "Handler function %s is not decorated with controller.handler" % (
- handle_func
- )
+ mtype, obj = self.event_queue.get(timeout=timeout)
+ if mtype not in Events:
+ raise exceptions.ControlException("Unknown event %s" % repr(mtype))
+ handle_func = getattr(self, mtype)
+ if not callable(handle_func):
+ raise exceptions.ControlException("Handler %s not callable" % mtype)
+ if not handle_func.__dict__.get("__handler"):
+ raise exceptions.ControlException(
+ "Handler function %s is not decorated with controller.handler" % (
+ handle_func
)
- handle_func(obj)
- self.event_queue.task_done()
- changed = True
+ )
+ handle_func(obj)
+ self.event_queue.task_done()
+ changed = True
except queue.Empty:
pass
return changed