kopia lustrzana https://github.com/micropython/micropython-lib
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>pull/880/head
rodzic
84ba452113
commit
2b3bd5b7e0
|
@ -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:
|
||||
|
|
Ładowanie…
Reference in New Issue