diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2018-04-02 20:50:10 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@corte.si> | 2018-04-07 08:59:08 +1200 |
commit | 0fa1280daa94729defa8411d86266bd2b52ad0b6 (patch) | |
tree | d2a179d8ea16268483baf70204fa0920d902bc6a /mitmproxy/controller.py | |
parent | cdbe6f97af6ae86f80080b7a279c8d3734662c5c (diff) | |
download | mitmproxy-0fa1280daa94729defa8411d86266bd2b52ad0b6.tar.gz mitmproxy-0fa1280daa94729defa8411d86266bd2b52ad0b6.tar.bz2 mitmproxy-0fa1280daa94729defa8411d86266bd2b52ad0b6.zip |
asyncio simplify: we don't need a queue for proxy->main loop comms
Instead, we just schedule coroutines directly onto the core loop.
Diffstat (limited to 'mitmproxy/controller.py')
-rw-r--r-- | mitmproxy/controller.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/mitmproxy/controller.py b/mitmproxy/controller.py index 79b049c9..3b4c3092 100644 --- a/mitmproxy/controller.py +++ b/mitmproxy/controller.py @@ -8,10 +8,10 @@ class Channel: The only way for the proxy server to communicate with the master is to use the channel it has been given. """ - def __init__(self, loop, q, should_exit): + def __init__(self, master, loop, should_exit): + self.master = master self.loop = loop self.should_exit = should_exit - self._q = q def ask(self, mtype, m): """ @@ -22,7 +22,10 @@ class Channel: exceptions.Kill: All connections should be closed immediately. """ m.reply = Reply(m) - asyncio.run_coroutine_threadsafe(self._q.put((mtype, m)), self.loop) + asyncio.run_coroutine_threadsafe( + self.master.addons.handle_lifecycle(mtype, m), + self.loop, + ) g = m.reply.q.get() if g == exceptions.Kill: raise exceptions.Kill() @@ -34,7 +37,10 @@ class Channel: then return immediately. """ m.reply = DummyReply() - asyncio.run_coroutine_threadsafe(self._q.put((mtype, m)), self.loop) + asyncio.run_coroutine_threadsafe( + self.master.addons.handle_lifecycle(mtype, m), + self.loop, + ) NO_REPLY = object() # special object we can distinguish from a valid "None" reply. |