Home
Categories
Dictionary
Glossary
Download
Project Details
Changes Log
What Links Here
FAQ
License

Python modules overview



Python modules are modules which are scripted in the Python scripting language. There are two kinds of Python modules:
  • Modules which communicate with the associated Python script using UDP or TCP sockets
  • Modules which communicate with the associated Python script using http requests

Python scripts using UDP or TCP sockets

These Python modules allow to execute Python code in any Python 2 or Python 3 environment:
  • A Python module creates a Python process using the Python executable path defined in the framework properties. By default the framework will look for a Python 2.x executable among the applications installed on the System
  • The started Python process will execute a specified Python script
  • Services reception from the Python module will be deferred to the associated Python script using an UDP communication
  • Services invocation from the Python script will be deferred as a Python module Service invocation using an UDP communication

pythonarchi
Two generic additional Python scripts are necessary to handle the communication between the Python module and the Python script:
  • The pythonModule.py script is responsible for the Services subscription in the Python environment
  • The pythonUtils.py script is an utility script usable by the user Python script


The fact that the Python script is executed by a Python process started by the framework allows to use any Python version for the script, and even to use various different versions for different scripts (Python 2, Python 3, etc...).

Python library

Main Article: Python module

In order for the Python script to work properly, you must copy two additional Python scripts which will be used as a library in the same directory as the script itself:
  • The pythonModule.py script
  • The pythonUtils.py script
These two supporting scripts do not depend on the content of the Python script and can be retrieved in the Browser by performing the command Tools => Generate Python Library.

Python scripts using http requests

These Python modules allow to execute Python in a Python 3 environment:
  • A Python module creates a Python process using the Python executable path defined in the framework properties. By default the framework will look for a Python 3.x executable among the applications installed on the System
  • The started Python process will execute a specified Python script
  • Services reception and invocation will use http requests

pythonarchihttp
Two generic additional Python scripts are necessary to handle the communication between the Python module and the Python script:
  • The pythonHttpModule.py script is responsible for the Services subscription in the Python environment
  • The pythonHttpUtils.py script is an utility script usable by the user Python script
The scripts used by the module use the http.client and json modules, so this Python implementation require Python 3.

Python http library

Main Article: Python module

In order for the Python script to work properly, you must copy two additional Python scripts which will be used as a library in the same directory as the script itself:
  • The pythonHttpModule.py script
  • The pythonHttpUtils.py script
These two supporting scripts do not depend on the content of the Python script and can be retrieved in the Browser by performing the command Tools => Generate Python Library.

Debugging Python modules

Main Article: Debugging scripts

As for all scripts, the framework help debugging the Python scripts by showing the Python SctackTrace in case of an execution error in the script.

If the debugScripts property is turned on, the framework will additionnally show a Popup window allowing to navigate in the source for the Stack trace for the first encountered exception. For example:
pythondebug

Example

In the following example, the FlightManagementSystem module:
  • subscribe to the position publish service
  • subscribe to the directTo event service
  • provides the computeFlightPlan request-response service
      <pythonModule name="FlightManagementSystem" >
         <pythonImplementation path="pythonAppli"/>
         <interfaces>
            <subscribe service="position" />
            <eventReceived service="directTo"/>
            <requestReceived service="computeFlightPlan"/>
         </interfaces>
      </pythonModule>
Another way to specify the Python module is to explictly specify the ports and port sizes for the Java / Python communication:
      <pythonModule name="FlightManagementSystem" >
         <pythonImplementation path="pythonAppli" inputPort="6000" outputPort="6005" inputSize="1024" outputSize="1024"/>
         <interfaces>
            <subscribe service="position" />
            <eventReceived service="directTo"/>
            <requestReceived service="computeFlightPlan"/>
         </interfaces>
      </pythonModule>


We could have the following code for the script:
      from pythonUtils import PythonUtils

      class PythonAppli:
        def subscribe(self, pythonUtils, serviceName):
        service = pythonUtils.getService(serviceName)
        if serviceName == "position":
        // get position
        ...
        elif serviceName == "directTo":
        // compute directTo
        ...
        elif serviceName == "computeFlightPlan":
        // compute FlightPlan and sends the response
        ...

See also


Categories: concepts | python

Copyright 2017-2020 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence