aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/addonmanager.py
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2017-10-26 19:56:59 +0200
committerMaximilian Hils <git@maximilianhils.com>2017-10-26 21:43:59 +0200
commit7314081b8232ac8da8f0f893bad065806454c374 (patch)
tree9e58a3dc11d05bff7000b0bc1fdc9727f09f39f2 /mitmproxy/addonmanager.py
parent671b012e38fa0e3bbda379ac5bf5eab2cfd845e8 (diff)
downloadmitmproxy-7314081b8232ac8da8f0f893bad065806454c374.tar.gz
mitmproxy-7314081b8232ac8da8f0f893bad065806454c374.tar.bz2
mitmproxy-7314081b8232ac8da8f0f893bad065806454c374.zip
make safecall threadsafe.
Diffstat (limited to 'mitmproxy/addonmanager.py')
-rw-r--r--mitmproxy/addonmanager.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/mitmproxy/addonmanager.py b/mitmproxy/addonmanager.py
index 31665548..70cfda30 100644
--- a/mitmproxy/addonmanager.py
+++ b/mitmproxy/addonmanager.py
@@ -8,6 +8,7 @@ from mitmproxy import exceptions
from mitmproxy import eventsequence
from mitmproxy import controller
from mitmproxy import flow
+from mitmproxy import log
from . import ctx
import pprint
@@ -54,7 +55,13 @@ class StreamLog:
@contextlib.contextmanager
def safecall():
- stdout_replacement = StreamLog(ctx.log.warn)
+ # resolve ctx.master here.
+ # we want to be threadsafe, and ctx.master may already be cleared when an addon prints().
+ tell = ctx.master.tell
+ # don't use master.add_log (which is not thread-safe). Instead, put on event queue.
+ stdout_replacement = StreamLog(
+ lambda message: tell("log", log.LogEntry(message, "warn"))
+ )
try:
with contextlib.redirect_stdout(stdout_replacement):
yield