mirror of
https://github.com/infiniteCable2/panda.git
synced 2026-02-18 17:23:52 +08:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user