130 likes | 147 Views
Learn about training, development, and integration of Python clients for ACS services. Explore Python's pros and cons, available features, and simple examples.
E N D
ACS Training Developing Python Clients
Python’s Pros • Good stability • Faster start-up time than Java • Execution time usually sufficient, although not comparable to C++ • Fastest development time • Fewer lines of code, easy to understand if not too complex • Good for asynchronous, distributed testing • Ideal to allow users (astronomers) to control program behavior through scripts ACS Training
Python’s Cons • No compile-time checking: code inconsistencies only discovered at run-time in forms of software errors • Therefore not well suited for production software that has a large code base and gets maintained by different developers • Free tool support not as good as for Java (profilers, remote debugging, IDEs, …) ACS Training
What’s Available in Python? • If it’s been implemented in the ACS C++ or Java APIs chances are it also exists in Python or no one has asked for it yet. • Only major thing missing is XML support in the form of “helper” classes. ACS Training
Very Simple Example from Acspy.Clients.SimpleClient import PySimpleClient simpleClient = PySimpleClient() #Make an instance of the PySimpleClient remoteComponent="MOUNT2_LOOP" try: mount = simpleClient.getComponent(remoteComponent) actAzProperty = mount._get_actAz() #Get the actAz property (azm, compl) = actAzProperty.get_sync() #Get the value of the property print "MOUNT actual azimuth: ", azm simpleClient.releaseComponent(remoteComponent) except Exception, e: print "Sorry, maybe there was no",remoteComponent,"object" print "The exception was:", e simpleClient.disconnect() ACS Training
Callback Example from Acspy.Clients.SimpleClient import PySimpleClient import ACS, ACS__POA # Import the Python CORBA stubs for BACI from time import sleep class MyMonitor(ACS__POA.CBdouble): '''This class defines method(s) that will be invoked asynchronously by the mount device''' #------------------------------------------------------------------ def __init__ (self, propName = None): if propName != None: self.propName = propName else: self.propName = "NoName" #------------------------------------------------------------------ ACS Training
Callback Example (continued) def working (self, value, completion, desc): ''' Method that does all the real work. Parameters: value = the double we are interested in completion = completion structure desc = callback struct description ''' print "Working: ", str(self.propName), " is ", str(value) #------------------------------------------------------------------ def done (self, value, completion, desc): ''' Invoked just before a monitor is destroyed. Parameters: value = the final value of the double we are interested in completion = completion structure desc = callback struct description ''' print "Done: ", str(self.propName), " is ", str(value) ACS Training
Callback Example (continued) def negotiate (self, time_to_transmit, desc): '''For simplicities sake, we always return true. ''' return TRUE #-------------------------------------------------------------------- simpleClient = PySimpleClient() try: mount = simpleClient.getComponent("MOUNT2_LOOP") actAzProperty = mount._get_actAz() #Get the actAz property cbMon = MyMonitor("actAz") #Create a callback monitor for actAz cbMonServant = cbMon._this() #Activate the callback monitor desc = ACS.CBDescIn(0L, 0L, 0L) #Create the real monitor actMon = actAzProperty.create_monitor(cbMonServant, desc) actMon.set_timer_trigger(10000000) #Working method once per sec. sleep(10) #Destroy the monitor after ten seconds actMon.destroy() ACS Training
Callback Example (continued) # Release the component simpleClient.releaseComponent("MOUNT2_LOOP") except Exception, e: print "Sorry, I expected there to be a Mount in the system and" print "there isn't." print "The exception was:", e simpleClient.disconnect() ACS Training
What methods does PySimpleClient have? Every Python Container Service method is available in Python!!! See the Pydoc documentation for the ContainerServices class. ACS Training
Python-related Makefile Targets • PY_SCRIPTS - Specifies Python scripts without the .py extension that will be installed into $INTROOT/bin. • PY_MODULES – Specifies Python modules with the .py extension that will be installed into $INTROOT/lib/python/site-packages. • PY_PACKAGES – Specifies Python packages to be installed into $INTROOT/lib/python/site-packages. Really these are just directories containing Python scripts. ACS Training
Questions about Python Clients??? ACS Training
Demo ACS Training