Consider an object of a class: c = C()
. c
is imported in multiple parts of my program. During runtime, database operations happen that modify an attribute x
of c
(c.x = y
) in one script, but other scripts are running simultaneously and I want them to load the change immediately. How can I "reload" c
in memory everywhere it is used without having to rerun the scripts that use it?
I have read this:
And it recommends using the python reload() function to reload the module in memory. It would be great if I could tell every file that imports c
to reload it, but only to do so when c.x
is modified. How can I do this? I know that if we do:
c = C()
print(c.x)
c.x = y
print(c.x)
then the change will be reflected immediately, but this is within the same script. I have other scripts running simultaneously and I want the same thing to happen to the instances of c
in those other scripts.