测试在linux上可以正常gracefully exit

后期AFK了,工作太忙了
This commit is contained in:
Jerry Yan 2022-06-08 11:21:42 +08:00
parent 2444545dc1
commit 51e262762a
3 changed files with 10 additions and 1 deletions

View File

@ -43,6 +43,9 @@ class IOutput():
def other_output(self, message_type: str, message_raw: bytes):
...
def debug_output(self, message_type: str, message_raw: str):
...
def error_output(self, message_type: str, message_raw: bytes, exception: Exception):
...

View File

@ -122,7 +122,8 @@ class OutputManager():
self.decode_payload(message)
def terminate(self):
self._should_exit.set()
if self._should_exit:
self._should_exit.set()
MESSAGE_QUEUE.put(None)
for writer in self._writer:

View File

@ -18,6 +18,7 @@ _manager: "Optional[ProxyManager]" = None
class ProxyManager:
def __init__(self):
self._mitm_instance = None
self._loop: "Optional[asyncio.AbstractEventLoop]" = None
opts = Options(
listen_host=config()['mitm']['host'],
listen_port=config()['mitm']['port'],
@ -34,6 +35,9 @@ class ProxyManager:
self.terminate()
def terminate(self):
if self._loop:
if self._loop.is_running():
self._loop.stop()
if self._mitm_instance:
self._mitm_instance.shutdown()
@ -42,6 +46,7 @@ class ProxyManager:
def _start(self):
loop = asyncio.new_event_loop()
self._loop = loop
asyncio.set_event_loop(loop)
self._mitm_instance.run()