1 / 13

ACS Training

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

dholder
Télécharger la présentation

ACS Training

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ACS Training Developing Python Clients

  2. 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

  3. 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

  4. 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

  5. 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

  6. 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

  7. 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

  8. 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

  9. 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

  10. What methods does PySimpleClient have? Every Python Container Service method is available in Python!!! See the Pydoc documentation for the ContainerServices class. ACS Training

  11. 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

  12. Questions about Python Clients??? ACS Training

  13. Demo ACS Training

More Related