Skip to content

Commit

Permalink
examples: use context manager in detection_callback.py
Browse files Browse the repository at this point in the history
If we don't use a context manager, then we can get the following error
after a CTRL+C:

    Exception ignored in: <function BleakScannerWinRT.start.<locals>.<lambda> at 0x0000020C3A76EE80>
    Traceback (most recent call last):
    File "C:\Users\david\Documents\GitHub\bleak\bleak\backends\winrt\scanner.py", line 238, in <lambda>
        lambda s, e: event_loop.call_soon_threadsafe(self._received_handler, s, e)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\david\AppData\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 840, in call_soon_threadsafe
        self._check_closed()
    File "C:\Users\david\AppData\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 541, in _check_closed
        raise RuntimeError('Event loop is closed')
    RuntimeError: Event loop is closed
  • Loading branch information
dlech committed Jul 2, 2024
1 parent 3d2b0ec commit 28d26b6
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions examples/detection_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ async def main(args: argparse.Namespace):

while True:
logger.info("(re)starting scanner")
await scanner.start()
await asyncio.sleep(5.0)
await scanner.stop()
async with scanner:
await asyncio.sleep(5.0)


if __name__ == "__main__":
Expand Down

0 comments on commit 28d26b6

Please sign in to comment.