Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch all exit-related exceptions in order to safely shut down the BLE connection #25

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions irobot_edu_sdk/backend/bluetooth_desktop.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Licensed under 3-Clause BSD license available in the License file. Copyright (c) 2020-2022 iRobot Corporation. All rights reserved.
# Licensed under 3-Clause BSD license available in the License file. Copyright (c) 2020-2023 iRobot Corporation. All rights reserved.
#

"""
Expand Down Expand Up @@ -49,10 +49,11 @@ async def connect(self):
self._address = device.address
self._device = device
break
print(f'Connecting to {device.name} ({device.address})')
if self._device:
print(f'Connecting to {device.name} ({device.address})')
self._client = BleakClient(self._device)
else:
print(f'Connecting to {self._address}')
self._client = BleakClient(self._address)

if await self._client.connect():
Expand Down
7 changes: 6 additions & 1 deletion irobot_edu_sdk/robot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Licensed under 3-Clause BSD license available in the License file. Copyright (c) 2020-2022 iRobot Corporation. All rights reserved.
# Licensed under 3-Clause BSD license available in the License file. Copyright (c) 2020-2023 iRobot Corporation. All rights reserved.
#

try:
Expand Down Expand Up @@ -92,7 +92,12 @@ def __init__(self, backend: Backend):

self.sound_enabled = True

# Catch all signals and direct to the _exit_handler
signal.signal(signal.SIGINT, _exit_handler)
signal.signal(signal.SIGTSTP, _exit_handler)
signal.signal(signal.SIGQUIT, _exit_handler)
signal.signal(signal.SIGHUP, _exit_handler)
signal.signal(signal.SIGTERM, _exit_handler)

def __enter__(self):
return self
Expand Down