Skip to content

Commit

Permalink
prevent device double closing
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianPugh committed Feb 15, 2023
1 parent 81cd5f6 commit 11f7f6a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion belay/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,14 +650,19 @@ def __exit__(self, exc_type, exc_value, exc_tb):
def close(self) -> None:
"""Close the connection to device."""
# Invoke all teardown executers prior to closing out connection.
if self._board is None:
# Has already been closed
return

atexit.unregister(self.close)

self._board.cancel_running_program()

for executer in _sort_executers(self._belay_teardown._belay_executers):
executer()

return self._board.close()
self._board.close()
self._board = None

def reconnect(self, attempts: Optional[int] = None) -> None:
"""Reconnect to the device and replay the command history.
Expand Down

0 comments on commit 11f7f6a

Please sign in to comment.