Move running() in to .tick() method to make sure it's called consistently

This commit is contained in:
Aldo Cortesi 2017-03-14 11:41:20 +13:00
parent b745428b5c
commit 1b301ad5bb
1 changed files with 4 additions and 4 deletions

View File

@ -42,6 +42,7 @@ class Master:
self.event_queue = queue.Queue() self.event_queue = queue.Queue()
self.should_exit = threading.Event() self.should_exit = threading.Event()
self.server = server self.server = server
self.first_tick = True
channel = controller.Channel(self.event_queue, self.should_exit) channel = controller.Channel(self.event_queue, self.should_exit)
server.set_channel(channel) server.set_channel(channel)
@ -76,20 +77,19 @@ class Master:
def run(self): def run(self):
self.start() self.start()
running = False
try: try:
while not self.should_exit.is_set(): while not self.should_exit.is_set():
# Don't choose a very small timeout in Python 2: # Don't choose a very small timeout in Python 2:
# https://github.com/mitmproxy/mitmproxy/issues/443 # https://github.com/mitmproxy/mitmproxy/issues/443
# TODO: Lower the timeout value if we move to Python 3. # TODO: Lower the timeout value if we move to Python 3.
self.tick(0.1) self.tick(0.1)
if not running:
running = True
self.addons.invoke_all_with_context("running")
finally: finally:
self.shutdown() self.shutdown()
def tick(self, timeout): def tick(self, timeout):
if self.first_tick:
self.first_tick = False
self.addons.invoke_all_with_context("running")
with self.handlecontext(): with self.handlecontext():
self.addons("tick") self.addons("tick")
changed = False changed = False