pythonDefaultRuntime
property to python3
if you don't set the Python runtime explicitly[1]
GET
requestPOST
requestpythonHttpModule.py
script is responsible for the Services subscription in the Python environmentpythonHttpUtils.py
script is an utility script usable by the user Python scriptpythonHttpModule
element. For example:<pythonHttpModule name="FlightManagementSystem">The optional
pythonModuleType
attribute specifies the type of http communication. It can be:pythonImplementation
element declares the Python script file which implements the script, and specified associated properties:path
: refer to the name of the file (without the ".py" extension) which implements the Python script. The path of this file is by default relative to the application.xml
file which declares the moduleport
: define the port which will be used to communicate between the Java application and the Python ScriptpythonEnumAsString
: an optional boolean to specify that enumeration values should be sent as names to the Python module rather than their index. See Enumerations as String for more informationclassName
: the optional name of the Python class to call. By default the name is derived from the name of the Python module. See Python class name for more informationcompatibility
: Allows to set a compatibility for an older version of the Python modules. See Python compatibility for more information<pythonHttpModule name="FlightManagementSystem" > <pythonImplementation path="pythonAppli" port="8080"/> </pythonHttpModule>
myPythonAppli.py
, then the path parameter must be myPythonAppli
, and the class defined in the module must be named MyPythonAppli
.<pythonHttpModule name="FlightManagementSystem" id="1" > <pythonImplementation path="pythonAppli" port="8080"/> </pythonHttpModule>and:
from pythonHttpUtils import PythonHttpUtils class PythonAppli:However, it is possible to specify the name of the class to call in the module by using the
className
parameter.<pythonHttpModule name="FlightManagementSystem" > <pythonImplementation path="pythonAppli" className="FMS" port="8080" /> </pythonHttpModule>and:
from pythonHttpUtils import PythonHttpUtils class FMS:
PythonHttpUtils
class in the pythonHttpUtils
modulestart(self)
method, it will be called at startfrom pythonHttpUtils import PythonHttpUtils class PythonAppli: def start(self): self.pythonHttpUtils.startTimer('timer', 1, self.tick)
pythonEnumAsString
property specifies that the state names should be sent instead. Note that this can also be configured with the framework property of the same name.
eventReceived
, requestSend
and subscribe
notificationseventSend
, requestReceived
and push
invocationspythonHttpModule.py
and pythonHttpUtils.py
scripts must be updated when the communication between Java and Python is upgraded.pythonHttpModule.py
script check if its own version is compatible with the version proviced by Java. This means that you normally should replace the pythonHttpModule.py
and pythonHttpUtils.py
scripts if the Python modules version changes.
pythonHttpModule.py
scriptpythonHttpUtils.py
scriptpythonHttpUtils.py
script utility has the following utility methods:class PythonHttpUtils |
---|
var | CHANGED
Value indicating that a service has changed since the last notify call
|
---|
var | INVALID
Value indicating that a service declaration is invalid
|
---|
var | NOT_CHANGED
Value indicating that a service has not changed since the last notify call
|
---|
var | VALID
Value indicating that a service declaration is valid
|
---|
def | echo(self, content, wait=True)
print the content on the system.out Stream. Note that due to the rate of exchange between Java and Python, this method force a flush. Using only
print(content) would not print the content in many cases. |
---|
def | err(self, content, wait=True)
print the content on the system.err Stream. Note that due to the rate of exchange between Java and Python, this method force a flush. Using only
print(content) would not print the content in many cases. |
---|
def | getService(self, name)
get a Service with its name
|
---|
def | invoke(self, name)
Invoke a service
|
---|
def | notify(self, name, instanceId=0)
Get the content of one service for one instance
|
---|
def | setValue(self, service, name, value)
set a Data value for a Service
|
---|
def | startTimer(self, name, seconds, theMethod)
Start a timer loop. The method has the following arguments:
|
---|
value = service[data_name]
GET
request named /proto/api/notify/<serviceName>
for each service for which the module is subscribed to[6]
POST
request named /proto/api/invoke/<serviceName>
for each service for which the module is a provider. This request allow to invoke the servicePOST
request named /proto/api/stdout/
for sending a message to the frameworkPOST
request named /proto/api/stderr/
for sending an exception message to the frameworkpythonHttpUtils
script which take care of the sending of these requests automatically.
notify(self, name, instanceId=0)
method allow to get the content of a service. The method will return:PythonHttpUtils.INVALID
if the service does not existPythonHttpUtils.CHANGED
if the service has been updated since the last time its request has been sentPythonHttpUtils.UNCHANGED
if the service has not been updated since the last time its request has been sentPythonHttpUtils.ERROR
if a JSON decoding error has been encounteredinvoke(self, name)
method allow to invoke a service. The method will return:PythonHttpUtils.VALID
if the service does existPythonHttpUtils.INVALID
if the service does not exist<pythonHttpModule name="PublishModule" pythonModuleType="http"> <pythonImplementation path="pythonAppli" port="8080"/> <interfaces> <eventReceived service="event"/> <push service="published"/> </interfaces> </pythonHttpModule>The following code updates the value of the
published
service, depending on the event value:def tick(self): self.pythonHttpUtils.notify("event") eventService = self.pythonHttpUtils.getService(serviceName); eventValue = eventService["event"] if eventValue: step = -1 else: step = 1 publishService = self.pythonHttpUtils.getService("published"); self.pythonHttpUtils.setValue(publishService, "value", self.count) r1 = self.pythonHttpUtils.invoke("published") self.count = self.count + step
Copyright 2017-2020 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence