I am trying to auto update Cython .so modules that my python program uses on the fly. After I download the new module and del module
and import module
Python seems to still be importing the older version.
From this question, I've tried this but it didn't work:
from importlib import reload
import pyximport
pyximport.install(reload_support=True)
import module as m
reload(m)
From this question, I've also tried this and it didn't work either:
del sys.modules['module']
del module
import module
I've also tried this with no success:
from importlib import reload
import my_module
my_module = reload(my_module)
Any idea how I can get Cython .SO files imported on the fly?
EDIT: Adding code for update check and download
update_filename = "my_module.cpython-37m-darwin.so"
if __name__ == '__main__':
response = check_for_update()
if response != "No new version available!":
print (download_update(response))
def check_for_update():
print("MD5 hash: {}".format(md5(__file__)))
s = setup_session()
data = {
"hash": md5(__file__),
"type": "md5",
"platform": platform.system()
}
response = s.post(UPDATE_CHECK_URL, json=data)
return response.text
def download_update(url):
s = setup_session()
with s.get(url, stream=True) as r:
r.raise_for_status()
with open(update_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
if chunk:
f.write(chunk)
return update_filename
After it has downloaded the new SO file, I manually typed the commands I listed above.