Skip to content

Commit b697f99

Browse files
committed
target: add set_connection()
Add a method to set the connection for the current thread within the target. This method returns the connection that was previously set.
1 parent 9661c6b commit b697f99

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

devlib/target.py

+6
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,12 @@ def get_connection(self, timeout=None):
313313
raise ValueError('Connection class not specified on Target creation.')
314314
return self.conn_cls(timeout=timeout, **self.connection_settings) # pylint: disable=not-callable
315315

316+
def set_connection(self, conn):
317+
tid = id(threading.current_thread())
318+
old_conn = self._connections.get(tid)
319+
self._connections[tid] = conn
320+
return old_conn
321+
316322
def wait_boot_complete(self, timeout=10):
317323
raise NotImplementedError()
318324

doc/target.rst

+7
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,13 @@ Target
184184
blocking operation (e.g. using ``background()``) while at the same
185185
time doing something else in the same host-side thread.
186186

187+
.. method:: Target.set_connection(conn)
188+
189+
Set the Target's connection for the current thread to the one specified
190+
(typically, one that has previously been returned by the call to
191+
``get_connection``). Returns the old connection to the current thread -- it
192+
is up to the caller to keep track of it and restore it if they wish.
193+
187194
.. method:: Target.setup([executables])
188195

189196
This will perform an initial one-time set up of a device for devlib

0 commit comments

Comments
 (0)