mirror of
https://github.com/ARM-software/devlib.git
synced 2025-01-30 17:50:46 +00: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:
parent
c9b539f722
commit
f5f06122f3
@ -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.')
|
||||
|
Loading…
x
Reference in New Issue
Block a user