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

Python initialization and runtime sequence



This article explains the initialization and runtime sequence of Python socket modules.

Overview

The initialization and runtime sequence of Python scripts follows two general phases: Note that if the initialization phase does not end correctly[1]
It can be the case if the Python script takes too much time to start-up, or if there is an exception during the initialization of the script
, then the Python module initialization will be aborted. Else the runtime phase will be started.
sequencepython

Initialization phase

The initialization phase follows the following steps:
  • The Python script is started using the specified Python executable in a separate process
  • The pythonModule.py script sends a "STARTED" message to the Python module
  • If a init EntryPoint was provided, the Python script specific init method is called. See Python module initialization for more information
  • The Python script specific init method is called[2]
    This method is called only if the init(self, pythonUtils) method is specified for the Python script
    , and the pythonModule.py script sends a "INIT" message to the Python module
If all went well, at this point the Python module is initialized, and the runtime phase is started. Note that the Python module initialization will be aborted if:
sequencepythonstartjson
Note that before Python modules version 1.4, or if JSON is not supported by the Python module, the initialization sequence is a little different. See Python initialization sequence for version 1.3.

Python module initialization

The Python module receives a JSON content with the "-INIT-" key and the properties array as values, and the Python script specific init method is called. This method is called only if the init(self, pythonUtils) method is specified for the Python script.

The Python module will be able to retriefe the properties with the following methods of the pythonUtils script:
  • def hasProperty(self, name) returns true if there is a property will the specified name
  • def getProperty(self, name) returns the property value will the specified name
For example, suppose that we have the following Python module specification:
      <pythonModule name="module1">
         <pythonImplementation path="pythonAppli">
            <initEntryPoint method="init" />
         </pythonImplementation>
         <interfaces>
            <subscribe service="service1" />
            <push service="service2"  attach="attach"/>
         </interfaces>
         <properties>
            <property key="propBool" type="boolean" />
            <property key="propString" type="string" />
            <property key="propInt" type="int" />
         </properties>
      </pythonModule>
We can retrieve the properties values with the following code:
      def init(self, pythonUtils):
        theIntProperty = pythonUtils.getProperty("propInt")
        theIntProperty = pythonUtils.getProperty("propString")
        theBoolProperty = pythonUtils.getProperty("propBool")

Runtime phase

The runtime phase follows the following steps:
  • The Python script specific start method is called[5]
    This method is called only if the start(self, pythonUtils) method is specified for the Python script
  • Then the Python script will be notified for every services reception by the module, and the script can send services to the framework through the pythonUtils.py script

sequencepythonruntime

Using lengthy methods for the Python scripts

If you have some code for initializing your Python script which takes a lot of time to complete, you can either:
  • Put this code in the def __init__(self)( method, and make sure that the waitAtStart value if sufficient
  • Put this code in the def init(self, pythonUtils)( method, and make sure that the waitAtInit value if sufficient

For Python http modules, only the first option is possible.

Notes

  1. ^ It can be the case if the Python script takes too much time to start-up, or if there is an exception during the initialization of the script
  2. ^ This method is called only if the init(self, pythonUtils) method is specified for the Python script
  3. ^ If not specified, the value is set to 200 ms
  4. ^ If not specified, the value is set to 500 ms
  5. ^ This method is called only if the start(self, pythonUtils) method is specified for the Python script

See also


Categories: concepts | python

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