Uh oh!
There was an error while loading. Please reload this page.
Use target connections as contexts. - #465
Conversation
setrofim
commented
Jan 30, 2020
Cc @douglas-raillard-arm: this should be largely orthogonal to #450, I believe, but FYI, just in case. |
| 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. |
| target.execute('ls') # uses conn rather than the default connection. | ||
| ``` | ||
| If the connection object is being uses withn another function, you do not need |
| target.execute('ls') # uses conn rather than the default connection. | ||
| ``` | ||
| If the connection object is being uses withn another function, you do not need |
| .. _multiple-connections: | ||
| Multipe Connections With One Target |
There was a problem hiding this comment.
Is it worth adding a note somewhere that Gem5Connections and TelnetConnections do not support this?
There was a problem hiding this comment.
Good point. I'll add a note for Gem5Connection. TelnetConnection actually derives from SshConnection so it would be supported.
There was a problem hiding this comment.
In which case for TelnetConnection, a call to the BaseConnectioniniti method will also need to be added.
There was a problem hiding this comment.
Ah, yes. Good catch. Fixed.
| .. method:: _wait_for_boot(self) | ||
| Wait for the gem5 simulated system to have booted and finished the booting animation. | ||
There was a problem hiding this comment.
Update the info on line 19 about a common base?
Add a method to set the connection for the current thread within the target. This method returns the connection that was previously set.
You might want to take the patches that fixes thread local variables to store the connection first, they somehow conflicts, especially on the I can submit them in a separate PR if needed. There is also a |
setrofim
commented
Jan 30, 2020
Ah cool, I'll hold off on this then, until that is merged, and will then add the changes to that. One nit -- could you rename the file to |
Add a base class for connection objects that implements the context manager interface and keeps track of the connection's target (which gets set by Target.get_connection). When used as a context manager, the connection substitutes itself for the target's default connection for the thread within the context using Target.set_connect(). The old connection is restored upon exiting the context.
douglas-raillard-arm
commented
May 8, 2024
I think this PR is stale as quite a lot of things has changed since then in that area, but it would be pretty easy to implement these days with something like that: classTarget:
...
@contextlib.contextmanagerdefwith_connection(self, conn):
old=self.conntry:
self.conn=connyieldfinally:
self.conn=old
|
Make it easier to use multiple connections to the target from the same thread.