Skip to content

Commit 2b3bd5b

Browse files
committed
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 <damien@micropython.org>
1 parent 84ba452 commit 2b3bd5b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

micropython/bluetooth/aioble/multitests/ble_write_order.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ async def instance0_task():
4444

4545
# Register characteristic.written() handlers as asyncio background tasks.
4646
# The order of these is important!
47-
asyncio.create_task(task_written(characteristic_second, "second"))
48-
asyncio.create_task(task_written(characteristic_first, "first"))
47+
task_second = asyncio.create_task(task_written(characteristic_second, "second"))
48+
task_first = asyncio.create_task(task_written(characteristic_first, "first"))
4949

5050
# This dummy task simulates background processing on a real system that
5151
# can block the asyncio loop for brief periods of time
52-
asyncio.create_task(task_dummy())
52+
task_dummy_ = asyncio.create_task(task_dummy())
5353

5454
multitest.globals(BDADDR=aioble.config("mac"))
5555
multitest.next()
@@ -63,6 +63,10 @@ async def instance0_task():
6363

6464
await connection.disconnected()
6565

66+
task_second.cancel()
67+
task_first.cancel()
68+
task_dummy_.cancel()
69+
6670

6771
async def task_written(chr, label):
6872
while True:

0 commit comments

Comments
 (0)