I have an issue re-running a script in spyder, which dynamically tabulates some of its own attributes.
Here is a minimal example that is representative of what I am doing. I have a source script that I run with the normal Run (F5) command. It runs in the same directory that it lives in:
runfile('C:/some/path/test.py', wdir='C:/some/path')
test.py
import sys
def x():
pass
def y():
pass
x.add = y.add = True
if __name__ == '__main__':
a = [obj for obj in tuple(sys.modules[__name__].__dict__.values())
if getattr(obj, 'add', False)]
print(a)
I can re-run this script a couple of times, and always get the same expected result:
[<function x at 0x0000025E793DBD90>, <function y at 0x0000025E793DB598>]
I would expect that if I change the name of one of the functions, say from x
to f
, and the attribute assignment to f.add = y.add = True
, I would get the same result, but with x
changed to f
. Instead, I get
[<function x at 0x0000025E793DB510>, <function y at 0x0000025E793DBBF8>, <function f at 0x0000025E793DBA60>]
Given that the new function f
shows up in the list, but the old x
is still there as well, I think that the module cache for the script is not being cleared properly.
I have been manually clearing the workspace using the eraser button over the console, but I feel like there must be a better solution, or at least an explanation of what is happening. Perhaps it is an issue with UMR?
I am running Spyder 3.3.3 with the following: Python 3.7.3 64-bit | Qt 5.9.6 | PyQt5 5.9.2 | Windows 10, IPython 7.4.9