mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
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.
This commit is contained in:
parent
deffed2196
commit
5b2d1c044a
@ -110,24 +110,21 @@ class Master(object):
|
|||||||
def tick(self, timeout):
|
def tick(self, timeout):
|
||||||
changed = False
|
changed = False
|
||||||
try:
|
try:
|
||||||
# This endless loop runs until the 'Queue.Empty'
|
mtype, obj = self.event_queue.get(timeout=timeout)
|
||||||
# exception is thrown.
|
if mtype not in Events:
|
||||||
while True:
|
raise exceptions.ControlException("Unknown event %s" % repr(mtype))
|
||||||
mtype, obj = self.event_queue.get(timeout=timeout)
|
handle_func = getattr(self, mtype)
|
||||||
if mtype not in Events:
|
if not callable(handle_func):
|
||||||
raise exceptions.ControlException("Unknown event %s" % repr(mtype))
|
raise exceptions.ControlException("Handler %s not callable" % mtype)
|
||||||
handle_func = getattr(self, mtype)
|
if not handle_func.__dict__.get("__handler"):
|
||||||
if not callable(handle_func):
|
raise exceptions.ControlException(
|
||||||
raise exceptions.ControlException("Handler %s not callable" % mtype)
|
"Handler function %s is not decorated with controller.handler" % (
|
||||||
if not handle_func.__dict__.get("__handler"):
|
handle_func
|
||||||
raise exceptions.ControlException(
|
|
||||||
"Handler function %s is not decorated with controller.handler" % (
|
|
||||||
handle_func
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
handle_func(obj)
|
)
|
||||||
self.event_queue.task_done()
|
handle_func(obj)
|
||||||
changed = True
|
self.event_queue.task_done()
|
||||||
|
changed = True
|
||||||
except queue.Empty:
|
except queue.Empty:
|
||||||
pass
|
pass
|
||||||
return changed
|
return changed
|
||||||
|
Loading…
Reference in New Issue
Block a user