aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/master.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2018-04-04 14:52:24 +1200
committerAldo Cortesi <aldo@corte.si>2018-04-07 09:04:14 +1200
commit9dcd15d350aa5e2ee2d6f7299d0183cabddeb992 (patch)
treeb02a58edf7402c3f0f9a898a71d9e384bea4ecf2 /mitmproxy/master.py
parent6a08ef465f3af6cb2044baf98279de1071538f5a (diff)
downloadmitmproxy-9dcd15d350aa5e2ee2d6f7299d0183cabddeb992.tar.gz
mitmproxy-9dcd15d350aa5e2ee2d6f7299d0183cabddeb992.tar.bz2
mitmproxy-9dcd15d350aa5e2ee2d6f7299d0183cabddeb992.zip
asyncio: ditch the handler context
There are a few reasons for this. First, logs are now async, and can be called at any time. Second, the event loop is thread local, so there can only ever be one master per thread. These two things together completely obviate the need for a handler context.
Diffstat (limited to 'mitmproxy/master.py')
-rw-r--r--mitmproxy/master.py21
1 files changed, 4 insertions, 17 deletions
diff --git a/mitmproxy/master.py b/mitmproxy/master.py
index 323f73dc..4e17e538 100644
--- a/mitmproxy/master.py
+++ b/mitmproxy/master.py
@@ -1,5 +1,4 @@
import threading
-import contextlib
import asyncio
import logging
@@ -58,6 +57,10 @@ class Master:
self.waiting_flows = []
self.log = log.Log(self)
+ mitmproxy_ctx.master = self
+ mitmproxy_ctx.log = self.log
+ mitmproxy_ctx.options = self.options
+
@property
def server(self):
return self._server
@@ -67,22 +70,6 @@ class Master:
server.set_channel(self.channel)
self._server = server
- @contextlib.contextmanager
- def handlecontext(self):
- # Handlecontexts also have to nest - leave cleanup to the outermost
- if mitmproxy_ctx.master:
- yield
- return
- mitmproxy_ctx.master = self
- mitmproxy_ctx.log = self.log
- mitmproxy_ctx.options = self.options
- try:
- yield
- finally:
- mitmproxy_ctx.master = None
- mitmproxy_ctx.log = None
- mitmproxy_ctx.options = None
-
def start(self):
self.should_exit.clear()
if self.server: