createSubProcess(self, instance, scriptName, fileName, wait=True)
method of the pythonHttpUtils
class and give the following arguments:instance
: An instance of any class which will be used for the http communication with the framework, and which will also be responsible for all the functionality of the spawned instancescriptName
: A script which will be used to unmarshall the instance after creating the sub-processfileName
: the name of the TEMP file which will be use to marshall the instancewait
(optional, True by default): specifies if the . You should set it to False
if you want to span more than one processpythonHttpUtils
class marshall the instance in the provided TEMP file using pickle, and create a sub-process with the provided scriptsetupAfterLoad(self)
method of the pythonHttpUtils
class. This part is necessary because pickle does not keep the fields belonging to other modules when unmarshallingpythonHttpUtils
class. ThesetupAfterLoad(self)
method will use these arguments to recreate the content of the services map in the pythonHttpUtils
instance after unmarshallingPythonInstance
and create the sub process with Popen:from pythonHttpUtils import PythonHttpUtils from pyAppClass import PythonInstance class PythonAppli: def start(self): instance = PythonInstance(self.pythonHttpUtils) p = self.pythonHttpUtils.createSubProcess(instance, 'pyAppScript.py', 'app.pkl')The
pyAppScript.py
script has the following code:import pickle, sys # Get the adress of the serialized app class and unmarshall it strAppFile = sys.argv[1] app = pickle.load(open(strAppFile, 'rb')) # setup the parameter of the internal pythonHttpUtils field app.pythonHttpUtils.setupAfterLoad() # there the app is completely functional and can communicate with the framework
Copyright 2017-2020 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence