As I understood:
- something is needed to be loaded
- it is needed to be loaded often, because file with code which uses this something is edited often
- you don't want to wait until it will be loaded every time
Maybe such solution will be okay for you.
You can write script loader file in such way:
import importlib.util, traceback, sys
# Example data
something = [123]
modules_before = list(sys.modules.keys())
while True:
# Change according the file name
spec = importlib.util.spec_from_file_location('some_file', 'some_file.py')
mod = importlib.util.module_from_spec(spec)
# Change to needed global name in the target module
mod.something = something
try:
spec.loader.exec_module(mod)
except KeyboardInterrupt:
raise
except:
traceback.print_exc()
del mod, spec
modules_after = list(sys.modules.keys())
for k in modules_after:
if k not in modules_before:
del sys.modules[k]
# Press enter to restart
print('Press enter to re-run, CTRL-C to exit')
sys.stdin.readline()
Example of module:
# Change 1 to some different number when first script is running and press enter
something[0] += 1
print(something)
Should work. And should reduce the reload time of pickle close to zero π
CPPCPPCPPCPPCPPCPPCPPCPPCPPCPP
- 1k
- 5
- 17