-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use target connections as contexts. #465
base: master
Are you sure you want to change the base?
Conversation
Cc @douglas-raillard-arm: this should be largely orthogonal to #450, I believe, but FYI, just in case. |
doc/target.rst
Outdated
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/s/coller/caller.
doc/connection.rst
Outdated
target.execute('ls') # uses conn rather than the default connection. | ||
``` | ||
|
||
If the connection object is being uses withn another function, you do not need |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uses->used
doc/connection.rst
Outdated
target.execute('ls') # uses conn rather than the default connection. | ||
``` | ||
|
||
If the connection object is being uses withn another function, you do not need |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/s/withn/within
|
||
.. _multiple-connections: | ||
|
||
Multipe Connections With One Target |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth adding a note somewhere that Gem5Connections and TelnetConnections do not support this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In which case for TelnetConnection
, a call to the BaseConnection
initi
method will also need to be added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes. Good catch. Fixed.
@@ -249,3 +249,32 @@ The only methods discussed below are those that will be overwritten by the | |||
.. 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
252a4ff
to
77cada6
Compare
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 |
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.
77cada6
to
3327ea1
Compare
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: class Target:
...
@contextlib.contextmanager
def with_connection(self, conn):
old = self.conn
try:
self.conn = conn
yield
finally:
self.conn = old
|
Make it easier to use multiple connections to the target from the same thread.