Writing LabRAD Servers (2) - syue99/Lab_control GitHub Wiki
Methods in the LabradServer class explained
initServer
Just to init a server.
stopServer
The stopServer method is meant for cleanup actions that have to be called when the server is required to stop. This method is executed, for example, when the node server stops running the given server, or whenever the server exits with an error such as the identification error. #needlink.
Since it's not known ahead of time when stopServer may get called, it's important account for any possible state of the server. Suppose some big object is created in initServer and requires to be cleaned up upon exiting:
def initServer():
self.my_object = big_object()
One should not simply use self.my_object.cleanup() in stopServer because stopServer may get called even before initServer is executed. This would happen with the identification error #needlink. Instead use:
def stopServer():
if hasattr(self, 'my_object'):
self.my_object.cleanup()
Perhaps more pythonic is:
def stopServer():
try:
self.my_object.cleanup():
except AttributeError:
pass
Note that stopServer may return a deferred, which means that one can yield inside the method. with additional @inlineCallbacks decorator. #needlink
initContext
Initial a context.