OpenVMS Source Code Demos

Python JIT Compiler

1) the following information applies to all implementations of python3 on all systems
2) on OpenVMS systems: directory definitions are wrapped with square brackets
3) the PVM (python virtual machine) used here is cpython-310 (an implementation of python 3.10.0 written in C)
4) imported libraries are always case sensitive
5) file extensions:
py (python source code)
pyc (python compiled)

edit: 2023-08-20

How it is supposed to work:

  • Directly invoke python script hello_world.py
    • the script is compiled to bytecode in memory which is then executed via the PVM (python virtual machine)
    • the bytecode is discarded when the PVM exits
  • Indirectly invoke python script hello_world.py
    execute this DCL command python hello_world_loader.py start
    "import hello_world" looks for source file hello_world.py
    look at timestamp of file hello_world.py
    look for subfolder [.__pycache__]
    look for bytecode file [.__pycache__]hello_world.cpython-310.pyc
    compare timestamps
    if pyc is after py then run

    [.__pycache__]hello_world.cpython-310.pyc

    stop 1
    compile py script then saves pyc [.__pycache__]hello_world.cpython-310.pyc
    (could result in the creation of a sub folder)

    python executes [.__pycache__]hello_world.cpython-310.pyc stop 2
  • Notice that the PVM version name is combined with the source code name when writing the bytecode file. If the Python PVM is updated then this JIT process would automatically compile and save new bytecode files using the new version name.

Python-3.10.0 on OpenVMS-8.4

  • I have noticed an intermittent problem with the python3-10.0 implementation on OpenVMS because executing hello_world_loader.py causes a newly compiled version of [.__pycache__]hello_world.cpython-310.pyc to be generated during each execution. Doing it this way would actually be a slowdown rather than a speedup.
  • Solution:
    • this only happens with original scripts created with either the EDT or EVE editors which produce variable-length RMS text records
    • if the scripts were created with either the VI or VIM editors, or copied via SFTP from a Linux system, then the files will be in stream-LF format which caused the problem to disappear. The following procedure can be used to create a new file with the desired properties.
      ! first we need a foreign command
      $ rfmstmlf :== convert/fdl="""record; format stream_lf"""
      ! now we use the foreign command to convert the file to stream_lf
      $ rfmstmlf targetfile.txt
# ======================================================
# title   : hello_world_loader.py
# platform: OpenVMS-8.4-1H1 I64 (Itanium)
# author  : Neil Rieck
# created : 2023-08-08 # usage : python hello_world_loader.py # ====================================================== import hello_world hello_world.main()

# ======================================================
# title   : hello_world.py
# platform: OpenVMS-8.4-1H1 I64 (Itanium)
# author  : Neil Rieck
# created : 2023-08-08 # usage : # 1) python hello_world.py (compiles to memory every time) # 2) import then run from another script # note: see 'hello_world_loader.py' in this folder # ====================================================== def main(): print("hello world") if __name__ == "__main__": main()