![]() It’s fine for quick and dirty scripting, but once you are over 20-or-so lines of code, you should switch to an external text editor (of your choice). Maintainability matters!Īnother habit you should say goodbye to is using Maya’s script editor. And, apart from very simple utility libraries, your tools should not be written as a single python file. Now, you can scatter your code base with a bunch of reloads, but it’s bad practice and, eventually, you will mess up. What this built-in function does is, it reloads a single file modules. What we basically do by restarting Maya each time is we introduced the “compilation step”!Īs Raymond Hettinger would say: there must be a better way! But firstly… Python is supposed to be fast to iterate and fast to prototype with. I’ve done it myself! It’s needed because once imported, python module lives in memory and to refresh the memory you need to close the session and start anew.īut this is a huge waste of time. Using sys.executable ensures that the same python executable is used for the master python process and the subprocess, so that's more transparent.Far too often I’ve seen TDs close Maya and reopen it just to check how the changes they made to the tool they are creating is now running. If this is an operational case, I suggest that you have a master python program which creates the package, then use separate python processes to load it. That could explain the problem you're having. I have doubts about the feasability of reloading a module containing compiled code, reading this answer: which suggests that PEP 489 changed module reloading (between python 3.6 and 3.7), possibly "breaking" shared library reload.ĭue to limitations in shared library loading (both dlopen on POSIX and LoadModuleEx on Windows), it is not generally possible to load a modified library after it has changed on disk. What would be the correct way of doing this? It seems that my module never gets reloaded. Running the script again loads the correct module and shows the new time: Demos/helloworld$ python driver.py Writing /home/wuebbel/.local/lib/python3.7/site-packages/HelloWorld-2.1-p圓.7.egg-info Removing /home/wuebbel/.local/lib/python3.7/site-packages/HelloWorld-2.1-p圓.7.egg-info ![]() 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Ĭopying build/lib.linux-x86_64-3.7/helloworld.cpython-37m-x86_64-linux-gnu.so -> /home/wuebbel/.local/lib/python3.7/site-packages ![]() The module is imported, the main file is touched, it is compiled and installed, and then reloaded. Os.system("python3 setup.py install -user") I am compiling and loading with the following python script: import os It has a single function hello which returns the build time: return Py_BuildValue("s", _TIME_) The implementation is the spam example from the tutorial. ![]() I followed How do I unload (reload) a Python module?, but I cannot get it to work in this environment.įor 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. I am developing a C module, and it would be very handy to reload the module once it changed. How does module reload work in python 3.7.1? Setup and Summary
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |