Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 1, 2024
1 parent a284447 commit 2041d0b
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 70 deletions.
12 changes: 5 additions & 7 deletions src/aiotools/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,11 @@ async def cancel_all_tasks() -> None:
if task.cancelled():
continue
if task.exception() is not None:
loop.call_exception_handler(
{
"message": "unhandled exception during loop shutdown",
"exception": task.exception(),
"task": task,
}
)
loop.call_exception_handler({
"message": "unhandled exception during loop shutdown",
"exception": task.exception(),
"task": task,
})


def _worker_main(
Expand Down
18 changes: 8 additions & 10 deletions src/aiotools/supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,14 @@ def _on_task_done(self, task):
if self._parent_task.done():
# Not sure if this case is possible, but we want to handle
# it anyways.
self._loop.call_exception_handler(
{
"message": (
f"Task {task!r} has errored out but its parent "
f"task {self._parent_task} is already completed"
),
"exception": exc,
"task": task,
}
)
self._loop.call_exception_handler({
"message": (
f"Task {task!r} has errored out but its parent "
f"task {self._parent_task} is already completed"
),
"exception": exc,
"task": task,
})
return

if _is_base_error and not self._aborting and not self._parent_cancel_requested:
Expand Down
18 changes: 8 additions & 10 deletions src/aiotools/taskgroup/persistent.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,14 @@ async def _task_wrapper(
# we report it as soon as possible using the event loop's
# exception handler, instead of postponing
# to the timing when PersistentTaskGroup terminates.
loop.call_exception_handler(
{
"message": (
"Got an unhandled exception "
f"in the exception handler of Task {task!r}"
),
"exception": exc,
"task": task,
}
)
loop.call_exception_handler({
"message": (
"Got an unhandled exception "
f"in the exception handler of Task {task!r}"
),
"exception": exc,
"task": task,
})
finally:
del fut

Expand Down
19 changes: 11 additions & 8 deletions src/aiotools/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,16 @@ def patch_loop(self):
so that sleep instantly returns while proceeding the virtual clock.
"""
loop = get_running_loop()
with mock.patch.object(
loop._selector,
"select",
new=functools.partial(self._virtual_select, loop._selector.select),
), mock.patch.object(
loop,
"time",
new=self.virtual_time,
with (
mock.patch.object(
loop._selector,
"select",
new=functools.partial(self._virtual_select, loop._selector.select),
),
mock.patch.object(
loop,
"time",
new=self.virtual_time,
),
):
yield
11 changes: 7 additions & 4 deletions tests/test_ptaskgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,13 @@ async def handler(exc_type, exc_obj, exc_tb):

loop = aiotools.compat.get_running_loop()
vclock = aiotools.VirtualClock()
with vclock.patch_loop(), mock.patch.object(
loop,
"call_exception_handler",
mock.MagicMock(),
with (
vclock.patch_loop(),
mock.patch.object(
loop,
"call_exception_handler",
mock.MagicMock(),
),
):
# Errors in exception handlers are covered by the event loop's exception
# handler, so that they can be reported as soon as possible when they occur.
Expand Down
30 changes: 14 additions & 16 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,24 +172,22 @@ def write(self, msg):
self.writer(f"log:{proc_idx}:{msg}")

log_stream = _LogAdaptor(write)
logging.config.dictConfig(
{
"version": 1,
"handlers": {
"console": {
"class": "logging.StreamHandler",
"stream": log_stream,
"level": "DEBUG",
},
logging.config.dictConfig({
"version": 1,
"handlers": {
"console": {
"class": "logging.StreamHandler",
"stream": log_stream,
"level": "DEBUG",
},
"loggers": {
"aiotools": {
"handlers": ["console"],
"level": "DEBUG",
},
},
"loggers": {
"aiotools": {
"handlers": ["console"],
"level": "DEBUG",
},
}
)
},
})
log = logging.getLogger("aiotools")
write(f"started:{proc_idx}")
log.debug("hello")
Expand Down
26 changes: 11 additions & 15 deletions tests/test_utils_as_completed.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@ async def test_as_completed_safe() -> None:
results = []
with VirtualClock().patch_loop():
async with aclosing(
as_completed_safe(
[
do_job(0.3, 1),
do_job(0.2, 2),
do_job(0.1, 3),
]
)
as_completed_safe([
do_job(0.3, 1),
do_job(0.2, 2),
do_job(0.1, 3),
])
) as ag:
async for result in ag:
results.append(await result)
Expand All @@ -56,14 +54,12 @@ async def test_as_completed_safe_partial_failure() -> None:
errors = []
with VirtualClock().patch_loop():
async with aclosing(
as_completed_safe(
[
do_job(0.1, 1),
fail_job(0.2),
do_job(0.3, 3),
fail_job(0.4),
]
)
as_completed_safe([
do_job(0.1, 1),
fail_job(0.2),
do_job(0.3, 3),
fail_job(0.4),
])
) as ag:
async for result in ag:
try:
Expand Down

0 comments on commit 2041d0b

Please sign in to comment.