1
0
mirror of https://github.com/ARM-software/devlib.git synced 2024-10-05 18:30:50 +01:00

target: Provide context manager API for Target

Allow cleanly disconnecting the Target object, so that we don't get
garbage output from __del__ later on when half of the namespace has
already disappeared.
This commit is contained in:
Douglas Raillard 2024-05-07 10:20:02 +01:00 committed by Marc Bonnici
parent c9b539f722
commit f5f06122f3

View File

@ -526,6 +526,18 @@ class Target(object):
if self._async_pool is not None:
self._async_pool.__exit__(None, None, None)
def __enter__(self):
return self
def __exit__(self, *args, **kwargs):
self.disconnect()
async def __aenter__(self):
return self.__enter__()
async def __aexit__(self, *args, **kwargs):
return self.__exit__(*args, **kwargs)
def get_connection(self, timeout=None):
if self.conn_cls is None:
raise ValueError('Connection class not specified on Target creation.')