reload - reloading dependent modules in Python -
let's have python script main.py imports othermodule.py. possible write reload(othermodule) in main.py when make changes othermodule.py, can still reload(main), reload othermodule?
well, it's not quite simple. assuming have main.py this...
import time import othermodule  foo = othermodule.foo() while 1:     foo.foo()     time.sleep(5)     reload(othermodule) ...and othermodule.py this...
class foo(object):     def foo(self):         print 'foo' ...then if change othermodule.py this...
class foo(object):     def foo(self):         print 'bar' ...while main.py still running, it'll continue print foo, rather bar, because foo instance in main.py continue use old class definition, although can avoid making main.py this...
import time import othermodule  while 1:     foo = othermodule.foo()     foo.foo()     time.sleep(5)     reload(othermodule) point is, need aware of sorts of changes imported modules cause problems upon reload().
might include of source code in original question, in cases, it's safest restart entire script.
Comments
Post a Comment