move global startup code into main methdod
This commit is contained in:
@@ -82,7 +82,7 @@ async def handle_client(reader: StreamReader, writer: StreamWriter, inv_class):
|
|||||||
await inv.local.ifc.server_loop()
|
await inv.local.ifc.server_loop()
|
||||||
|
|
||||||
|
|
||||||
async def handle_shutdown(web_task):
|
async def handle_shutdown(loop, web_task):
|
||||||
'''Close all TCP connections and stop the event loop'''
|
'''Close all TCP connections and stop the event loop'''
|
||||||
|
|
||||||
logging.info('Shutdown due to SIGTERM')
|
logging.info('Shutdown due to SIGTERM')
|
||||||
@@ -132,7 +132,7 @@ def get_log_level() -> int:
|
|||||||
return log_level
|
return log_level
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__": # pragma: no cover
|
def main(): # pragma: no cover
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('-c', '--config_path', type=str,
|
parser.add_argument('-c', '--config_path', type=str,
|
||||||
default='./config/',
|
default='./config/',
|
||||||
@@ -190,6 +190,8 @@ if __name__ == "__main__": # pragma: no cover
|
|||||||
|
|
||||||
if ConfigErr is not None:
|
if ConfigErr is not None:
|
||||||
logging.info(f'ConfigErr: {ConfigErr}')
|
logging.info(f'ConfigErr: {ConfigErr}')
|
||||||
|
return
|
||||||
|
|
||||||
logging.info('******')
|
logging.info('******')
|
||||||
|
|
||||||
Proxy.class_init()
|
Proxy.class_init()
|
||||||
@@ -214,11 +216,12 @@ if __name__ == "__main__": # pragma: no cover
|
|||||||
for signame in ('SIGINT', 'SIGTERM'):
|
for signame in ('SIGINT', 'SIGTERM'):
|
||||||
loop.add_signal_handler(getattr(signal, signame),
|
loop.add_signal_handler(getattr(signal, signame),
|
||||||
lambda loop=loop: asyncio.create_task(
|
lambda loop=loop: asyncio.create_task(
|
||||||
handle_shutdown(web_task)))
|
handle_shutdown(loop, web_task)))
|
||||||
|
|
||||||
loop.set_debug(log_level == logging.DEBUG)
|
loop.set_debug(log_level == logging.DEBUG)
|
||||||
try:
|
try:
|
||||||
if ConfigErr is None:
|
if ConfigErr is None:
|
||||||
|
global proxy_is_up
|
||||||
proxy_is_up = True
|
proxy_is_up = True
|
||||||
loop.run_forever()
|
loop.run_forever()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
@@ -229,3 +232,7 @@ if __name__ == "__main__": # pragma: no cover
|
|||||||
logging.debug('Close event loop')
|
logging.debug('Close event loop')
|
||||||
loop.close()
|
loop.close()
|
||||||
logging.info(f'Finally, exit Server "{serv_name}"')
|
logging.info(f'Finally, exit Server "{serv_name}"')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user