Skip to content

Commit

Permalink
Register Device.close with atexit
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianPugh committed Feb 14, 2023
1 parent a22818d commit 622e39f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions belay/device.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ast
import atexit
import concurrent.futures
import importlib.resources
import linecache
Expand Down Expand Up @@ -311,6 +312,8 @@ def __init__(
for executer in autoinit_executers:
executer()

atexit.register(self.close)

self.__post_init__()

def __pre_autoinit__(self):
Expand Down Expand Up @@ -647,6 +650,8 @@ 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.
atexit.unregister(self.close)

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

Expand Down

0 comments on commit 622e39f

Please sign in to comment.