Skip to content

Commit

Permalink
DEBUG/DROPME: Mac, what doing?
Browse files Browse the repository at this point in the history
  • Loading branch information
qstokkink committed Nov 25, 2024
1 parent 3ce7030 commit 3ca6990
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 6 additions & 2 deletions ipv8/taskmanager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import asyncio
import logging
import time
import traceback
Expand Down Expand Up @@ -253,8 +254,8 @@ async def after_cancel() -> None:

done_future.after_cancel_task = after_cancel() # type: ignore[attr-defined]
self.register_anonymous_task(f"[Catch shutdown] {basename}", catch_shutdown)
self.register_anonymous_task(f"[Run shutdown] {basename}",
shield(done_future.after_cancel_task)) # type: ignore[attr-defined]
self.register_anonymous_task(f"[Run shutdown] {basename}",
shield(done_future.after_cancel_task)) # type: ignore[attr-defined]

await sleep(0) # Enter both infinite loops

Expand Down Expand Up @@ -333,6 +334,9 @@ async def shutdown_task_manager(self) -> None:
if tasks:
with suppress(CancelledError):
await gather(*tasks)
for task in tasks: # TODO: Mac exits ``gather`` on ``cancelling``, not ``cancelled``.
while not task.done():
await sleep(0)


__all__ = ["TaskManager", "task"]
10 changes: 8 additions & 2 deletions ipv8/test/test_taskmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,13 @@ async def test_delayed_looping_call_register_wait_and_cancel(self) -> None:
self.assertTrue(task1.cancelled())
self.assertTrue(task2.cancelled())

def test_raise_on_duplicate_task_name(self) -> None:
async def test_raise_on_duplicate_task_name(self) -> None:
"""
Check that a normal register task cannot be used as a replace task.
"""
self.tm.register_task("test", lambda: None)
self.tm.register_task("test", lambda: None, delay=5)
await sleep(0)

with self.assertRaises(RuntimeError):
self.tm.register_task("test", lambda: None)

Expand Down Expand Up @@ -300,6 +302,10 @@ async def test_register_shutdown_task(self) -> None:
fut = await self.tm.register_shutdown_task("test", sub_manager.shutdown_task_manager)

await self.tm.shutdown_task_manager()

print()
print("Shutdown state sub manager", sub_manager._shutdown)
print(">", [str(task) for task in sub_manager.get_tasks()])

self.assertTrue(fut.done())
self.assertTrue(sub_fut.cancelled())
Expand Down

0 comments on commit 3ca6990

Please sign in to comment.