diff options
author | Aldo Cortesi <aldo@corte.si> | 2018-04-07 11:46:34 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@corte.si> | 2018-04-23 10:28:18 +1200 |
commit | 44016a0de519469792769f7b78c37e7de9bfde24 (patch) | |
tree | bd077442d797487df8aff9d7c0d3f6b76633b337 /mitmproxy/master.py | |
parent | f6b606b3643d0f447dac9830d25ac1853f8610fe (diff) | |
download | mitmproxy-44016a0de519469792769f7b78c37e7de9bfde24.tar.gz mitmproxy-44016a0de519469792769f7b78c37e7de9bfde24.tar.bz2 mitmproxy-44016a0de519469792769f7b78c37e7de9bfde24.zip |
asyncio: shift script reloading out of the tick event
The tick event is a nasty compromise, left over from when we didn't have an
event loop. This is the first patch in a series that explores moving our
built-in addons to managing coroutines on the eventloop directly for periodic
tasks.
Diffstat (limited to 'mitmproxy/master.py')
-rw-r--r-- | mitmproxy/master.py | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/mitmproxy/master.py b/mitmproxy/master.py index bbbd07d0..8eb01600 100644 --- a/mitmproxy/master.py +++ b/mitmproxy/master.py @@ -94,19 +94,14 @@ class Master: exc = None try: loop() - except Exception as e: + except Exception as e: # pragma: no cover exc = traceback.format_exc() finally: - if not self.should_exit.is_set(): + if not self.should_exit.is_set(): # pragma: no cover self.shutdown() - pending = asyncio.Task.all_tasks() loop = asyncio.get_event_loop() - try: - loop.run_until_complete(asyncio.gather(*pending)) - except Exception as e: - # When we exit with an error, shutdown might not happen cleanly, - # and we can get exceptions here caused by pending Futures. - pass + for p in asyncio.Task.all_tasks(): + p.cancel() loop.close() if exc: # pragma: no cover @@ -122,6 +117,7 @@ class Master: self.run_loop(loop.run_forever) async def _shutdown(self): + self.should_exit.set() if self.server: self.server.shutdown() loop = asyncio.get_event_loop() |