From 3485f7b6f0d3c6adcc93b57c168890a29524299a Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 12 Jun 2024 14:44:48 +1000 Subject: [PATCH] aioble/multitests: Store a reference to tasks and cancel when done. Storing references to tasks is required by CPython, and enforced by Ruff RUF006. In this case it's also reasonable to cancel these tasks once the test is finished. Signed-off-by: Damien George --- .../bluetooth/aioble/multitests/ble_write_order.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/micropython/bluetooth/aioble/multitests/ble_write_order.py b/micropython/bluetooth/aioble/multitests/ble_write_order.py index ca47f3837..24da54c2d 100644 --- a/micropython/bluetooth/aioble/multitests/ble_write_order.py +++ b/micropython/bluetooth/aioble/multitests/ble_write_order.py @@ -44,12 +44,12 @@ async def instance0_task(): # Register characteristic.written() handlers as asyncio background tasks. # The order of these is important! - asyncio.create_task(task_written(characteristic_second, "second")) - asyncio.create_task(task_written(characteristic_first, "first")) + task_second = asyncio.create_task(task_written(characteristic_second, "second")) + task_first = asyncio.create_task(task_written(characteristic_first, "first")) # This dummy task simulates background processing on a real system that # can block the asyncio loop for brief periods of time - asyncio.create_task(task_dummy()) + task_dummy_ = asyncio.create_task(task_dummy()) multitest.globals(BDADDR=aioble.config("mac")) multitest.next() @@ -63,6 +63,10 @@ async def instance0_task(): await connection.disconnected() + task_second.cancel() + task_first.cancel() + task_dummy_.cancel() + async def task_written(chr, label): while True: