Has anybody encountered the issue that code changes made to a Python program is only picked up once a brand new SB+ session is opened or completely logged out and back in?
This is UniVerse? While you remain in the SB+ subroutine tree, all previously called subroutines are cached for your session, so that you must escape to “real” TCL or log out and in to re-read for changes.
Yes this is UniVerse. The log out does work but the escape to “real” TCL
does not seem to do the trick.
Yes I have experienced this as well. In the XDEMO account I have created some of my own routines. Very simple. A UV basic program calls a python module/function that just prints something. I find that if I change the string that I am printing the output doesn’t change unless I LOG OUT OF MY SESSION, and log back in.
This seems very problematic for making changes to pyhton calls from UV basic.
I have not been able to replicate this, though I briefly thought I had it when I forgot that I had the same module name in different PP files in separate UV accounts, each printing different strings. The pyCallFunction() uses whichever one it finds first in the “u2.pth” configuration, even if you are logged in for UV purposes to the other UV account.
[Edit] I have not checked what precedence is followed when using multiple “.pth” files.
[Another edit] I found
"__pycache__" sub-directories in my “PP” directories, which might be worth investigating. Throwing
"__pycache__" into a search engine returns some interesting information.
Can you share code?
Python does not by default re-import a module if it is already imported. When developing the pythonic way of dealing with a change is to exit python and start a new session to insure you have a clean environment.
Yet, if you want to remove the module, so you can re-import it, I would recommend the sys module.
There is a modules object, and a method called “__delitem__” which removes a module.
__pycache__ directory seems to be the culprit. I have been able to successfully run modified code (only needed to refresh the python shell) after deleting the corresponding entry in the
__pycache__ directory. After some reading I found that you can avoid this by setting the environment variable PYTHONDONTWRITEBYTECODE to any non-empty string. This will stop the
__pycache__ entries from being created which in theory should give you “fresh” code with each execution in SB+ and/or each new python shell. Will let you know how if that works as expected.
There is also another way to compile the code once changed if you don’t want to purge the
__pycache__ directory: https://docs.python.org/3/library/py_compile.html
Glad it’s working for you