Is where a way to persist objects over re-execs of a running script? If I want a running script to re execute itself to pick up any code changes, (os.exec*) is there a way to persist the objects for access after the re-execution? I could set environment variables with pickled ascii data, or write that data to a pipe and re-read it after the re-execution, but that seems inelegant or like a hack. Even if doing that, not all items pickle well.
解决方案
If you put your code in a module, you can use the reload() standard function to load the new version of the code. Your main module could look like this:
import mymodule
while mymodule.go():
reload(mymodule)
Whenever you want to reload your module code, return True from go(). When you want to exit, return False.