From 29438c806c8e6961836345ae52c2c97fa9d4046a Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Thu, 23 Jan 2020 10:58:58 +0000 Subject: [PATCH] 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. --- devlib/target.py | 6 ++++++ doc/target.rst | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/devlib/target.py b/devlib/target.py index a75b4d08b..1247568d2 100644 --- a/devlib/target.py +++ b/devlib/target.py @@ -313,6 +313,12 @@ def get_connection(self, timeout=None): raise ValueError('Connection class not specified on Target creation.') return self.conn_cls(timeout=timeout, **self.connection_settings) # pylint: disable=not-callable + def set_connection(self, conn): + tid = id(threading.current_thread()) + old_conn = self._connections.get(tid) + self._connections[tid] = conn + return old_conn + def wait_boot_complete(self, timeout=10): raise NotImplementedError() diff --git a/doc/target.rst b/doc/target.rst index 57581045b..6b3710e6f 100644 --- a/doc/target.rst +++ b/doc/target.rst @@ -184,6 +184,13 @@ Target blocking operation (e.g. using ``background()``) while at the same time doing something else in the same host-side thread. +.. method:: Target.set_connection(conn) + + Set the Target's connection for the current thread to the one specified + (typically, one that has previously been returned by the call to + ``get_connection``). Returns the old connection to the current thread -- it + is up to the coller to keep track of it and restore it if they wish. + .. method:: Target.setup([executables]) This will perform an initial one-time set up of a device for devlib