diff options
author | Aldo Cortesi <aldo@corte.si> | 2018-04-01 11:37:35 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@corte.si> | 2018-04-01 11:37:35 +1200 |
commit | 3cc5d81a4a6cdb507b71fce0ce6c2a23fed0c208 (patch) | |
tree | e539bc868bf58f6fcb8adebcb3ea0928fc845303 /mitmproxy/master.py | |
parent | b6d943cfa3a226651e705ff45aa7154010ea29ba (diff) | |
download | mitmproxy-3cc5d81a4a6cdb507b71fce0ce6c2a23fed0c208.tar.gz mitmproxy-3cc5d81a4a6cdb507b71fce0ce6c2a23fed0c208.tar.bz2 mitmproxy-3cc5d81a4a6cdb507b71fce0ce6c2a23fed0c208.zip |
asyncio: fix channel interface and tests
We now need to synthesize a tick event when changing addons in tests, because
tick is asynchronously called on the event loop.
Diffstat (limited to 'mitmproxy/master.py')
-rw-r--r-- | mitmproxy/master.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/mitmproxy/master.py b/mitmproxy/master.py index c2d2b6a0..2f47ae09 100644 --- a/mitmproxy/master.py +++ b/mitmproxy/master.py @@ -1,7 +1,6 @@ import threading import contextlib import asyncio -import signal from mitmproxy import addonmanager from mitmproxy import options @@ -37,11 +36,16 @@ class Master: """ def __init__(self, opts): self.event_queue = asyncio.Queue() + self.should_exit = threading.Event() + self.channel = controller.Channel( + asyncio.get_event_loop(), + self.event_queue, + self.should_exit, + ) self.options = opts or options.Options() # type: options.Options self.commands = command.CommandManager(self) self.addons = addonmanager.AddonManager(self) - self.should_exit = threading.Event() self._server = None self.first_tick = True self.waiting_flows = [] @@ -52,7 +56,7 @@ class Master: @server.setter def server(self, server): - server.set_channel(controller.Channel(asyncio.get_event_loop(), self.event_queue)) + server.set_channel(self.channel) self._server = server @contextlib.contextmanager @@ -202,7 +206,7 @@ class Master: host = f.request.headers.pop(":authority") f.request.headers.insert(0, "host", host) - rt = http_replay.RequestReplayThread(self.options, f, self.server.channel) + rt = http_replay.RequestReplayThread(self.options, f, self.channel) rt.start() # pragma: no cover if block: rt.join() |