You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

30 lines
730 B

# -*- coding: utf-8 -*-
import asyncio
from functools import wraps
import jmclient # install asyncioreactor
from twisted.internet import reactor
from jmbase import jmprint
def wrap_main(func):
@wraps(func)
async def func_wrapper(*args, **kwargs):
try:
return await func(*args, **kwargs)
except SystemExit as e:
return e.args[0] if e.args else None
finally:
try:
for task in asyncio.all_tasks():
task.cancel()
if reactor.running:
reactor.stop()
except Exception as e:
jmprint(f'Errors during reactor cleaenup/stop: {e}', 'debug')
return func_wrapper