def getConnection(host=C.MANAGER_HOST, port=None, name="Python Client", password=None, tls_mode=C.MANAGER_TLS): """Connect to LabRAD and return a deferred that fires the protocol object.""" p = yield protocol.connect(host, port, tls_mode) yield p.authenticate(password) yield p.loginClient(name) returnValue(p)
def run(self): """Run the node in a loop, reconnecting after connection loss.""" log = logging.getLogger('labrad.node') while True: print('Connecting to {}:{}...'.format(self.host, self.port)) try: p = yield protocol.connect(self.host, self.port, self.tls_mode, self.username, self.password) node = NodeServer(self.nodename, self.host, self.port, p.credential) yield node.startup(p) except Exception: log.error('Node failed to start', exc_info=True) else: try: yield node.onShutdown() except Exception: log.error('Error during node shutdown', exc_info=True) ## hack: manually clear the internal message dispatcher dispatcher.connections.clear() dispatcher.senders.clear() dispatcher._boundMethods.clear() yield util.wakeupCall(0) print('Will try to reconnect in {} seconds...'.format(self.reconnectDelay)) yield util.wakeupCall(self.reconnectDelay)
def run(self): """Run the node in a loop, reconnecting after connection loss.""" log = logging.getLogger('labrad.node') while True: print 'Connecting to {}:{}...'.format(self.host, self.port) try: p = yield protocol.connect(self.host, self.port, self.tls_mode) yield p.authenticate(self.password) node = NodeServer(self.nodename, self.host, self.port, self.password) yield node.startup(p) except Exception: log.error('Node failed to start', exc_info=True) else: try: yield node.onShutdown() except Exception: log.error('Error during node shutdown', exc_info=True) ## hack: manually clear the internal message dispatcher dispatcher.connections.clear() dispatcher.senders.clear() dispatcher._boundMethods.clear() yield util.wakeupCall(0) print 'Will try to reconnect in {} seconds...'.format(self.reconnectDelay) yield util.wakeupCall(self.reconnectDelay)
def getConnection(host=C.MANAGER_HOST, port=None, name=None, password=None, tls_mode=C.MANAGER_TLS, username=None, headless=False): """Connect to LabRAD and return a deferred that fires the protocol object.""" name = name or 'Python Client ({})'.format(support.getNodeName()) p = yield protocol.connect(host, port, tls_mode, username, password, headless) yield p.loginClient(name) returnValue(p)
def run(srv): host = config['host'] port = int(config['port']) tls_mode = config['tls'] try: p = yield protocol.connect(host, port, tls_mode) yield p.authenticate(config['password']) yield srv.startup(p) yield srv.onShutdown() log.msg('Disconnected cleanly.') except Exception as e: log.msg('There was an error: {}'.format(e)) if stop_reactor: try: reactor.stop() except Exception: pass
def run(srv): host = config["host"] port = int(config["port"]) tls_mode = config["tls"] try: p = yield protocol.connect(host, port, tls_mode) yield p.authenticate(config["password"]) yield srv.startup(p) yield srv.onShutdown() log.msg("Disconnected cleanly.") except Exception as e: log.msg("There was an error: {}".format(e)) if stop_reactor: try: reactor.stop() except Exception: pass
def run(srv): host = config['host'] port = int(config['port']) tls_mode = config['tls'] try: p = yield protocol.connect(host, port, tls_mode, config['username'], config['password']) yield srv.startup(p) yield srv.onShutdown() log.msg('Disconnected cleanly.') except Exception as e: log.msg('There was an error: {}'.format(e)) if stop_reactor: try: reactor.stop() except Exception: pass
def start(self, dv): """Start the given DataVaultMultihead server. The server startup and shutdown logic changed in pylabrad 0.95, so we need separate logic to handle the old and new cases. Args: dv (DataVaultMultihead): The labrad server object that we want to start. Returns: A deferred that fires after the server has successfully started. This deferred contains a function that can be invoked to shutdown the server. That function itself returns a deferred that will fire when the shutdown is complete. """ if hasattr(dv, 'startup'): # pylabrad 0.95+ p = yield protocol.connect(self.host, self.port) yield p.authenticate(password=self.password) yield dv.startup(p) @inlineCallbacks def stop_func(): dv.disconnect() yield dv.onShutdown() else: # pylabrad 0.94 and earlier try: dv.configure_tls(self.host, "starttls") except AttributeError: self.report("pylabrad doesn't support TLS") cxn = TCPClient(self.host, self.port, dv) cxn.startService() yield dv.onStartup() @inlineCallbacks def stop_func(): yield cxn.stopService() returnValue(stop_func)
def run(self): """Run the node in a loop, reconnecting after connection loss.""" log = logging.getLogger('labrad.node') while True: print('Connecting to {}:{}...'.format(self.host, self.port)) try: p = yield protocol.connect(self.host, self.port, self.tls_mode, self.username, self.password) node = NodeServer(self.nodename, self.host, self.port, p.credential) yield node.startup(p) except Exception: log.error('Node failed to start', exc_info=True) else: try: yield node.onShutdown() except Exception: log.error('Error during node shutdown', exc_info=True) yield util.wakeupCall(0) print('Will try to reconnect in {} seconds...'.format(self.reconnectDelay)) yield util.wakeupCall(self.reconnectDelay)
def start_server(): p = yield protocol.connect(host, port, tls_mode) yield p.authenticate(password) yield srv.startup(p)
def start_server(): p = yield protocol.connect(host, port, tls_mode, username, password) yield srv.startup(p)