importlib does not work for run button
Hey guys, could you please help?
I got this script work with raw commandline but not working with run button.
if __name__ == '__main__':
import sys
import time
import importlib
import inspect
m = importlib.import_module('m1')
print(m) # module object
m.fun1() # hello world1
items = inspect.getmembers(m, inspect.isfunction)
print(dict(items))
time.sleep(10) # manually modify m1.py, to print hello world2
new_module = importlib.reload(sys.modules['m1'])
print(new_module)
items = inspect.getmembers(new_module, inspect.isfunction)
print(dict(items))
new_module.fun1() # still print hello world1
The raw commandline gives:
<module 'm1' from 'xxxx\\m1.py'>
hello world1
None
{'fun1': <function fun1 at 0x000001578E0CA5C0>, 'fun2': <function fun2 at 0x000001578E28A980>}
<module 'm1' from 'xxxx\\m1.py'>
{'fun1': <function fun1 at 0x000001578E28AAC0>, 'fun2': <function fun2 at 0x000001579158FC40>}
hello world2
The pycharm run commandline
xxxx\python.exe xxxx\main.py
<module 'm1' from 'xxxx\\m1.py'>
hello world1
None
{'fun1': <function fun1 at 0x000001578E0CA5C0>, 'fun2': <function fun2 at 0x000001578E28A980>}
<module 'm1' from 'xxxx\\m1.py'>
{'fun1': <function fun1 at 0x000001578E28AAC0>, 'fun2': <function fun2 at 0x000001579158FC40>}
hello world1
Please sign in to leave a comment.