diff options
Diffstat (limited to 'mitmproxy/tools')
-rw-r--r-- | mitmproxy/tools/console/master.py | 11 | ||||
-rw-r--r-- | mitmproxy/tools/main.py | 5 | ||||
-rw-r--r-- | mitmproxy/tools/web/master.py | 4 |
3 files changed, 10 insertions, 10 deletions
diff --git a/mitmproxy/tools/console/master.py b/mitmproxy/tools/console/master.py index 5cc1cf43..de660b17 100644 --- a/mitmproxy/tools/console/master.py +++ b/mitmproxy/tools/console/master.py @@ -1,3 +1,4 @@ +import asyncio import mailcap import mimetypes import os @@ -182,12 +183,6 @@ class ConsoleMaster(master.Master): ) self.ui.clear() - def ticker(self, *userdata): - changed = self.tick(timeout=0) - if changed: - self.loop.draw_screen() - self.loop.set_alarm_in(0.01, self.ticker) - def inject_key(self, key): self.loop.process_input([key]) @@ -206,6 +201,7 @@ class ConsoleMaster(master.Master): ) self.loop = urwid.MainLoop( urwid.SolidFill("x"), + event_loop=urwid.AsyncioEventLoop(loop=asyncio.get_event_loop()), screen = self.ui, handle_mouse = self.options.console_mouse, ) @@ -214,8 +210,6 @@ class ConsoleMaster(master.Master): self.loop.widget = self.window self.window.refresh() - self.loop.set_alarm_in(0.01, self.ticker) - if self.start_err: def display_err(*_): self.sig_add_log(None, self.start_err) @@ -236,6 +230,7 @@ class ConsoleMaster(master.Master): finally: sys.stderr.flush() super().shutdown() + self.addons.trigger("done") def shutdown(self): raise urwid.ExitMainLoop diff --git a/mitmproxy/tools/main.py b/mitmproxy/tools/main.py index 91488a1f..53c236bb 100644 --- a/mitmproxy/tools/main.py +++ b/mitmproxy/tools/main.py @@ -1,5 +1,6 @@ from __future__ import print_function # this is here for the version check to work on Python 2. +import asyncio import sys if sys.version_info < (3, 6): @@ -117,8 +118,10 @@ def run( def cleankill(*args, **kwargs): master.shutdown() - signal.signal(signal.SIGTERM, cleankill) + loop = asyncio.get_event_loop() + for signame in ('SIGINT', 'SIGTERM'): + loop.add_signal_handler(getattr(signal, signame), master.shutdown) master.run() except exceptions.OptionsError as e: print("%s: %s" % (sys.argv[0], e), file=sys.stderr) diff --git a/mitmproxy/tools/web/master.py b/mitmproxy/tools/web/master.py index 4c597f0e..b7eddcce 100644 --- a/mitmproxy/tools/web/master.py +++ b/mitmproxy/tools/web/master.py @@ -2,6 +2,8 @@ import webbrowser import tornado.httpserver import tornado.ioloop +from tornado.platform.asyncio import AsyncIOMainLoop + from mitmproxy import addons from mitmproxy import log from mitmproxy import master @@ -102,6 +104,7 @@ class WebMaster(master.Master): ) def run(self): # pragma: no cover + AsyncIOMainLoop().install() iol = tornado.ioloop.IOLoop.instance() @@ -109,7 +112,6 @@ class WebMaster(master.Master): http_server.listen(self.options.web_port, self.options.web_iface) iol.add_callback(self.start) - tornado.ioloop.PeriodicCallback(lambda: self.tick(timeout=0), 5).start() web_url = "http://{}:{}/".format(self.options.web_iface, self.options.web_port) self.add_log( |