Panda: context manager support (#1209)

* add __enter__ & __exit__ to Panda

* some examples

* another example

* even more

* use it here too
This commit is contained in:
Shane Smiskol
2023-01-13 16:17:20 -08:00
committed by GitHub
parent 520b9f1a8e
commit bdf39a451e
8 changed files with 30 additions and 32 deletions

View File

@@ -242,6 +242,12 @@ class Panda:
# reset comms
self.can_reset_communications()
def __enter__(self):
return self
def __exit__(self, *args):
self.close()
def close(self):
self._handle.close()
self._handle = None