Skip to content

Commit

Permalink
Don't log failed tasks; asyncio does that
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil Booth committed Mar 6, 2021
1 parent ac6ccbf commit 0abdd87
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 39 deletions.
6 changes: 1 addition & 5 deletions aiorpcx/curio.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@
)
from collections import deque
from contextlib import suppress
from functools import partial
import logging

from aiorpcx.util import instantiate_coroutine, check_task
from aiorpcx.util import instantiate_coroutine


__all__ = (
Expand All @@ -69,8 +67,6 @@ def spawn_sync(coro, *args, loop=None, daemon=False):
loop = loop or get_event_loop()
task = loop.create_task(coro)
task._daemon = daemon
if not daemon:
task.add_done_callback(partial(check_task, logging))
return task


Expand Down
8 changes: 0 additions & 8 deletions aiorpcx/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,3 @@ def signature_info(func):
other_names = None

return SignatureInfo(min_args, max_args, required_names, other_names)


def check_task(logger, task):
if not task.cancelled():
try:
task.result()
except Exception: # pylint: disable=broad-except
logger.error('task crashed: %r', task, exc_info=True)
7 changes: 3 additions & 4 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ ChangeLog
.. note:: The aiorpcX API changes regularly and is still unstable. I hope to finalize it
for a 1.0 release in the coming months.


Version 0.20.0 (06 Mar 2021)
Version 0.20.1 (06 Mar 2021)
----------------------------

* this release contains some significant API changes which users will need to carefully check
their code for.
* the report_crash argument to spawn() is renamed daemon and inverted. A daemon task's
result is ignored and crashes are not reported.
* the report_crash argument to spawn() is removed; instead a new one is named daemon. A
daemon task's exception (if any) is ignored by a TaskGroup.
* the join() method of TaskGroup (and so also when TaskGroup is used as a context manager)
does not raise the exception of failed tasks. The full semantics are precisely
described in the TaskGroup() docstring. Briefly: any task being cancelled or raising an
Expand Down
22 changes: 0 additions & 22 deletions tests/test_curio.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,28 +374,6 @@ async def test_tg_wait_bad():
await task


class MyLogger(object):
def __init__(self):
self.logged = False

def error(self, msg, *args, **kwargs):
self.logged = True


@pytest.mark.asyncio
async def test_logging(caplog):
for daemon in (True, False):
# spawn
task = await spawn(my_raises(TypeError), daemon=daemon)
try:
await task
assert False
except TypeError:
pass

assert any('TypeError' in record.message for record in caplog.records)


async def return_after_sleep(x, period=0.01):
await sleep(period)
return x
Expand Down

0 comments on commit 0abdd87

Please sign in to comment.