How to apply changes on a Python Script without restarting DIAdem?

Updated Dec 27, 2021

Environment

Software

  • DIAdem 2020
  • DIAdem 2020 SP1
  • DIAdem 2021

Changes on a Python module (Integrated to a Python Script in DIAdem) are not saved until a full restart of DIAdem is done.

DIAdem integrates Python into its own process to ensure fast access to functions and data. With "normal" Python scripts, Python.exe is terminated after each run. This is not the desired behavior when working with DIAdem. But you can reload changed modules with built-in Python functions.

Use the following function at the start of your Python Script:

import sys
if 'Importedmodule' not in sys.modules:
    import Importedmodule            # import module on first run
else:                     
    import importlib     
    importlib.reload(Importedmodule) # reload module on subsequent runs

and replace the value "Importedmodule" with the name of the module to be imported into the Python Script. 

This code works if you do not want to load the module twice on the first run.