Question
Adrian Maguire · Sep 16

Stopping IRIS processes caching Python code

We're having a problem with the way Python modules are being cached in Iris. If we modify some code and then reimport a module it is still processing the old code.

E.g. Create a python file:

helloWorld.py

def helloWorld() :
  return "Hello world"

The run the following in the Iris terminal:

SOURCENEW>set helloWorld = ##class(%SYS.Python).Import("helloWorld")
 
SOURCENEW>w helloWorld.helloWorld()
Hello world

Modify helloWorld.py

def helloWorld() :
  return "Hello world again"

In the same terminal process run the commands again, the same result is even though the code has been changed.

SOURCENEW>kill helloWorld
 
SOURCENEW>set helloWorld = ##class(%SYS.Python).Import("helloWorld")
 
SOURCENEW>w helloWorld.helloWorld()
Hello world

Only when I start a new process is the new code used.

Is there a way we can we stop the code from being cached without killing all the processes that have loaded it?

Product version: IRIS 2022.1
$ZV: IRIS for Windows (x86-64) 2022.1 (Build 209U) Tue May 31 2022 12:16:40 EDT
0
0 100
Discussion (2)1
Log in or sign up to continue

Try to reload like this:

set importlib = ##class(%SYS.Python).Import("importlib")
do importlib.reload(helloWorld)

Also, it not an IRIS-specific behavior, you'll get the same results in any python interpreter:

import helloWorld
helloWorld.helloWorld()
>'Hello world'
del helloWorld

# modify helloWorld.py in text editor

import helloWorld
helloWorld.helloWorld()
>'Hello world'

Thanks Eduard, that makes sense.


The problem we will have though is with csp gateway processes, since these processes can stay active for some time.


Is there a way we can stop these processes after a code change so they get a new instance of the python interpreter? I can do it manually using the web gateway, but we don't want to do this after every code change.

Also, when we deploy to live, we don't want to do this on every web server.