In my "scripting pydev" jython script I have a global variable called DEBUG, which toggles debug output and controls what events should trigger a reload of the script. During development I set this to True, and sure enough, debug output is shown and the correct listeners are registered at import time. However during runtime, no debug printouts are shown and a quick print statement clearly shows that DEBUG is now 0. However, if I rename the variable to eg DEBUG_LEFT_HAND_RANDOMISATION_ZXCAWDQWDXASDQWE, it remains True and debug output is shown also during runtime.
My guess is that jython scripts overwrite each other's vars at successive import, eg that some other preinstalled script (mine? :-) that is subsequently imported sets DEBUG to 0.
I don't know the mechanics behind the import, but I get the impression it's something like this:
scripting_globals = globals()
scripting_locals = locals()
for name in importables:
__import__(name, globals=scripting_globals, locals=scripting_locals)
This seems a bit awkward, and if not dangerous, then at least bug prone. Wouldn't it be better to use a clean environment for each import, such as:
scripting_globals = globals()
scripting_locals = locals()
for name in importables:
glob = scripting_globals.copy()
loc = scripting_locals.copy()
__import__(name, globals=glob, locals=loc)
Then again, I may be completely off and done messed this up all by myself :-)