aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/master.py
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2018-05-28 15:19:59 +0200
committerMaximilian Hils <git@maximilianhils.com>2018-05-28 22:27:14 +0200
commit1f6635c1fc5ebc9a629a4b5b572aef73e749bae1 (patch)
treea61c1afa87a6b3ba73e02bd8b80e3258ade7156b /mitmproxy/master.py
parent69aa5a0d2f799cc91ab5a7d5d75c55aa40ae58b8 (diff)
downloadmitmproxy-1f6635c1fc5ebc9a629a4b5b572aef73e749bae1.tar.gz
mitmproxy-1f6635c1fc5ebc9a629a4b5b572aef73e749bae1.tar.bz2
mitmproxy-1f6635c1fc5ebc9a629a4b5b572aef73e749bae1.zip
fix shutdown on Windows
This fixes #3133.
Diffstat (limited to 'mitmproxy/master.py')
-rw-r--r--mitmproxy/master.py10
1 files changed, 9 insertions, 1 deletions
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):
"""