How does module reload work in python 3.7.1?
Setup and Summary
I am running python 3.7.1 in Linux. I am developing a C module, and it would be very handy to reload the module once it changed. I followed How do I unload (reload) a Python module?, but I cannot get it to work in this environment.
For a demo of my problem, I wrote a simple module based on the SPAM example in the tutorial that returns the build time of the module. It will never get reloaded.
Code
The implementation is the spam example from the tutorial. It has a single function hello which returns the build time:
return Py_BuildValue("s", __TIME__);
I am compiling and loading with the following python script:
import os
import helloworld
print(helloworld.hello('test'))
os.system("touch helloworld.c")
os.system("python3 setup.py build")
os.system("python3 setup.py install --user")
from importlib import reload
helloworld=reload(helloworld)
print(helloworld.hello('test'))
The module is imported, the main file is touched, it is compiled and installed, and then reloaded.
Output
The module should show the new compilation time after reload, but the output does not change (I am leaving out some debug messages, the output is the first/last line, 08:04:20):
python driver.py
08:04:20
running build
running build_ext
building 'helloworld' extension
gcc ...
running install
running build
running build_ext
running install_lib
copying build/lib.linux-x86_64-3.7/helloworld.cpython-37m-x86_64-linux-gnu.so -> /home/wuebbel/.local/lib/python3.7/site-packages
running install_egg_info
Removing /home/wuebbel/.local/lib/python3.7/site-packages/HelloWorld-2.1-py3.7.egg-info
Writing /home/wuebbel/.local/lib/python3.7/site-packages/HelloWorld-2.1-py3.7.egg-info
08:04:20
Running the script again loads the correct module and shows the new time:
wuebbel@02e267406db3:~/Projekte/Mandelbrot Demos/helloworld$ python driver.py
08:16:58
...
08:16:58
It seems that my module never gets reloaded. What would be the correct way of doing this?