mitmproxy/examples/addons/nonblocking.py

18 lines
651 B
Python
Raw Normal View History

"""
Make events hooks non-blocking.
When event hooks are decorated with @concurrent, they will be run in their own thread, freeing the main event loop.
Please note that this generally opens the door to race conditions and decreases performance if not required.
"""
import time
2016-10-27 19:55:24 +00:00
from mitmproxy.script import concurrent
2014-09-08 14:02:31 +00:00
@concurrent # Remove this and see what happens
2016-07-08 01:37:33 +00:00
def request(flow):
# This is ugly in mitmproxy's UI, but you don't want to use mitmproxy.ctx.log from a different thread.
print(f"handle request: {flow.request.host}{flow.request.path}")
time.sleep(5)
print(f"start request: {flow.request.host}{flow.request.path}")