Presentation is loading. Please wait.

Presentation is loading. Please wait.

AtacamaLargeMillimeterArray ACS Training Developing Python Clients.

Similar presentations


Presentation on theme: "AtacamaLargeMillimeterArray ACS Training Developing Python Clients."— Presentation transcript:

1 AtacamaLargeMillimeterArray ACS Training Developing Python Clients

2 NRAO - Socorro, July 2004ACS Training2 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

3 NRAO - Socorro, July 2004ACS Training3 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, …)

4 NRAO - Socorro, July 2004ACS Training4 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.

5 NRAO - Socorro, July 2004ACS Training5 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()

6 NRAO - Socorro, July 2004ACS Training6 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" #------------------------------------------------------------------

7 NRAO - Socorro, July 2004ACS Training7 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)

8 NRAO - Socorro, July 2004ACS Training8 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()

9 NRAO - Socorro, July 2004ACS Training9 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()

10 NRAO - Socorro, July 2004ACS Training10 What methods does PySimpleClient have? Every Python Container Service method is available in Python!!! See the Pydoc documentation for the ContainerServicesContainerServices class.

11 NRAO - Socorro, July 2004ACS Training11 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.

12 NRAO - Socorro, July 2004ACS Training12 Questions about Python Clients???

13 NRAO - Socorro, July 2004ACS Training13 Demo


Download ppt "AtacamaLargeMillimeterArray ACS Training Developing Python Clients."

Similar presentations


Ads by Google