From b3dac1318410c72ea61d9c2c92bb19e68db377fd Mon Sep 17 00:00:00 2001 From: Jesson Soto Ventura Date: Thu, 31 Oct 2019 09:51:50 -0400 Subject: [PATCH 1/2] ctrl-c should prompt for an exit --- mitmproxy/tools/_main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mitmproxy/tools/_main.py b/mitmproxy/tools/_main.py index a00a3e989..11a873278 100644 --- a/mitmproxy/tools/_main.py +++ b/mitmproxy/tools/_main.py @@ -11,6 +11,7 @@ import signal import typing from mitmproxy.tools import cmdline +from mitmproxy.tools.console.master import ConsoleMaster from mitmproxy import exceptions, master from mitmproxy import options from mitmproxy import optmanager @@ -114,7 +115,10 @@ def run( loop = asyncio.get_event_loop() for signame in ('SIGINT', 'SIGTERM'): try: - loop.add_signal_handler(getattr(signal, signame), master.shutdown) + if isinstance(master, ConsoleMaster): + loop.add_signal_handler(getattr(signal, signame), master.prompt_for_exit) + else: + loop.add_signal_handler(getattr(signal, signame), master.shutdown) except NotImplementedError: # Not supported on Windows pass From 5cb1746ef667ff4a4c1426c959d6ce6a34d74540 Mon Sep 17 00:00:00 2001 From: Jesson Soto Ventura Date: Fri, 15 Nov 2019 23:22:38 -0500 Subject: [PATCH 2/2] used getattr to select exit --- mitmproxy/tools/_main.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/mitmproxy/tools/_main.py b/mitmproxy/tools/_main.py index 11a873278..0163e8d3e 100644 --- a/mitmproxy/tools/_main.py +++ b/mitmproxy/tools/_main.py @@ -11,7 +11,6 @@ import signal import typing from mitmproxy.tools import cmdline -from mitmproxy.tools.console.master import ConsoleMaster from mitmproxy import exceptions, master from mitmproxy import options from mitmproxy import optmanager @@ -115,10 +114,7 @@ def run( loop = asyncio.get_event_loop() for signame in ('SIGINT', 'SIGTERM'): try: - if isinstance(master, ConsoleMaster): - loop.add_signal_handler(getattr(signal, signame), master.prompt_for_exit) - else: - loop.add_signal_handler(getattr(signal, signame), master.shutdown) + loop.add_signal_handler(getattr(signal, signame), getattr(master, "prompt_for_exit", master.shutdown)) except NotImplementedError: # Not supported on Windows pass