show hidden uncaught errors in async Tasks
This commit is contained in:
parent
3f89ed4579
commit
6910b7ce1e
1 changed files with 19 additions and 0 deletions
|
@ -7,6 +7,7 @@ import asyncio
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
|
import typing
|
||||||
from docopt import docopt
|
from docopt import docopt
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
@ -21,6 +22,23 @@ log = logging.getLogger('lbry')
|
||||||
log.addHandler(logging.NullHandler())
|
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):
|
def display(data):
|
||||||
print(json.dumps(data, indent=2))
|
print(json.dumps(data, indent=2))
|
||||||
|
|
||||||
|
@ -241,6 +259,7 @@ def run_daemon(args: list, conf: Config):
|
||||||
logging.getLogger('aiohttp').setLevel(logging.CRITICAL)
|
logging.getLogger('aiohttp').setLevel(logging.CRITICAL)
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
|
loop.set_task_factory(task_factory)
|
||||||
|
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
log.setLevel(logging.DEBUG)
|
log.setLevel(logging.DEBUG)
|
||||||
|
|
Loading…
Add table
Reference in a new issue