-
Notifications
You must be signed in to change notification settings - Fork 10
Shared Connection Object
micramm edited this page Nov 21, 2013
·
10 revisions
The shared connection object allows multiple asynchronous clients to share a single connection to the manager. The clients work in their own unique contexts, maintaining complete independence. Additionally, the connection object helps the clients keep track of when a given server disconnects or reconnects to the manager. When such an event occurs, the client can use the connection object to automatically run a certain action like reacquiring the latest data from the server or disabling itself.
First, the asynchronous client has to important the connection object, and then connect i.e:
from connect import connection
@inlineCallbacks
def initialize(self):
self.cxn = connection()
yield self.cxn.connect()
Then it is necessary to acquire a unique connect context.
self.context = yield self.cxn.context()
Then can get access to any available server, and use that server in the acquired context:
server = yield self.cxn.get_server('Server Name')
yield server.method(..., context = self.context)