Compare commits

...

1 commit

Author SHA1 Message Date
Jack Robison
6910b7ce1e
show hidden uncaught errors in async Tasks 2019-10-01 11:33:42 -04:00

View file

@ -7,6 +7,7 @@ import asyncio
import argparse
import logging
import logging.handlers
import typing
from docopt import docopt
import aiohttp
@ -21,6 +22,23 @@ log = logging.getLogger('lbry')
log.addHandler(logging.NullHandler())
async def _task_decorator(coro: typing.Coroutine):
try:
return await coro
except asyncio.CancelledError:
raise
except BaseException as e:
log.exception('unhandled error in task')
raise e
def task_factory(loop: asyncio.AbstractEventLoop, coro: typing.Coroutine):
task = asyncio.tasks.Task(_task_decorator(coro), loop=loop)
if task._source_traceback:
del task._source_traceback[-1]
return task
def display(data):
print(json.dumps(data, indent=2))
@ -241,6 +259,7 @@ def run_daemon(args: list, conf: Config):
logging.getLogger('aiohttp').setLevel(logging.CRITICAL)
loop = asyncio.get_event_loop()
loop.set_task_factory(task_factory)
if args.verbose:
log.setLevel(logging.DEBUG)