aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.rst2
-rw-r--r--examples/keys.yaml2
-rw-r--r--mitmproxy/master.py10
-rw-r--r--mitmproxy/tools/main.py12
-rw-r--r--test/mitmproxy/proxy/test_server.py2
5 files changed, 21 insertions, 7 deletions
diff --git a/README.rst b/README.rst
index 7f67da1e..d7100374 100644
--- a/README.rst
+++ b/README.rst
@@ -171,7 +171,7 @@ with the following command:
:alt: Travis Build Status
.. |appveyor| image:: https://shields.mitmproxy.org/appveyor/ci/mitmproxy/mitmproxy/master.svg?label=appveyor%20ci
- :target: https://ci.appveyor.com/project/mhils/mitmproxy
+ :target: https://ci.appveyor.com/project/mitmproxy/mitmproxy
:alt: Appveyor Build Status
.. |coverage| image:: https://shields.mitmproxy.org/codecov/c/github/mitmproxy/mitmproxy/master.svg?label=codecov
diff --git a/examples/keys.yaml b/examples/keys.yaml
index a2b3d66a..ca7cee69 100644
--- a/examples/keys.yaml
+++ b/examples/keys.yaml
@@ -3,7 +3,7 @@
key: ctrl a
cmd: replay.client @marked
-
- # Bind key only in the lfowlist
+ # Bind key only in the flowlist
# Note that 1 is quoted, or YAML interprets it as a digit
key: "1"
ctx: ["flowlist"]
diff --git a/mitmproxy/master.py b/mitmproxy/master.py
index 20ac6acd..ecb8090b 100644
--- a/mitmproxy/master.py
+++ b/mitmproxy/master.py
@@ -119,7 +119,15 @@ class Master:
"""
if not self.should_exit.is_set():
self.should_exit.set()
- asyncio.run_coroutine_threadsafe(self._shutdown(), loop = self.channel.loop)
+ ret = asyncio.run_coroutine_threadsafe(self._shutdown(), loop=self.channel.loop)
+ # Weird band-aid to make sure that self._shutdown() is actually executed,
+ # which otherwise hangs the process as the proxy server is threaded.
+ # This all needs to be simplified when the proxy server runs on asyncio as well.
+ if not self.channel.loop.is_running(): # pragma: no cover
+ try:
+ self.channel.loop.run_until_complete(asyncio.wrap_future(ret))
+ except RuntimeError:
+ pass # Event loop stopped before Future completed.
def _change_reverse_host(self, f):
"""
diff --git a/mitmproxy/tools/main.py b/mitmproxy/tools/main.py
index 789bef63..acae9ee3 100644
--- a/mitmproxy/tools/main.py
+++ b/mitmproxy/tools/main.py
@@ -119,9 +119,6 @@ def run(
if extra:
opts.update(**extra(args))
- def cleankill(*args, **kwargs):
- master.shutdown()
- signal.signal(signal.SIGTERM, cleankill)
loop = asyncio.get_event_loop()
for signame in ('SIGINT', 'SIGTERM'):
try:
@@ -129,6 +126,15 @@ def run(
except NotImplementedError:
# Not supported on Windows
pass
+
+ # Make sure that we catch KeyboardInterrupts on Windows.
+ # https://stackoverflow.com/a/36925722/934719
+ if os.name == "nt":
+ async def wakeup():
+ while True:
+ await asyncio.sleep(0.2)
+ asyncio.ensure_future(wakeup())
+
master.run()
except exceptions.OptionsError as e:
print("%s: %s" % (sys.argv[0], e), file=sys.stderr)
diff --git a/test/mitmproxy/proxy/test_server.py b/test/mitmproxy/proxy/test_server.py
index 52970c9b..01ab068d 100644
--- a/test/mitmproxy/proxy/test_server.py
+++ b/test/mitmproxy/proxy/test_server.py
@@ -787,7 +787,7 @@ class TestServerConnect(tservers.HTTPProxyTest):
"""A replayed/fake response with no upstream_cert should not connect to an upstream server"""
self.set_addons(AFakeResponse())
assert self.pathod("200").status_code == 200
- asyncio.sleep(0.1)
+ await asyncio.sleep(0.1)
assert not self.proxy.tmaster.has_log("serverconnect")