Re: Reloading Python code without restarting the FreeCAD
Posted: Thu Feb 06, 2020 4:45 pm
The help and development forum of FreeCAD
https://forum.freecad.org/
You can hack your own reolad where you want.
Based on the above, I put femloader.py and fem.py in ~/.local/share/FreeCAD/Macro/. After I save fem.py it gets reloaded automatically. I was hoping freecad would already do such a thing already since it will ask "This has been modified outside of the source editor. Do you want to reload it?" for .FCMacro files. So it can likely be done more portably (without pyinotify).chrisb wrote: ↑Sun Mar 24, 2019 10:07 am I use sucessfully:Code: Select all
import someModule from importlib import reload reload(someModule)
Code: Select all
# femloader.py
import sys
import os.path
sys.path += ["/usr/lib/python3/dist-packages/"] # why is this here for accessing ubuntu's python3-pyinotify?
import pyinotify
import fem
from importlib import reload
def reload_fem(event):
reload(fem)
print(f"reloaded fem from {event.pathname}")
def reloader():
wm = pyinotify.WatchManager()
femfile = os.path.join(os.path.dirname(__file__) , "fem.py")
wm.add_watch(femfile, pyinotify.IN_MODIFY)
notifier = pyinotify.ThreadedNotifier(wm, reload_fem)
notifier.start()
return notifier
notifier = reloader()
If you want to reply, open a new topic, you are necrobumping a 3yo topic.aavogt wrote: ↑Thu Oct 05, 2023 9:13 pm ...
Based on the above, I put femloader.py and fem.py in ~/.local/share/FreeCAD/Macro/. After I save fem.py it gets reloaded automatically. I was hoping freecad would already do such a thing already since it will ask "This has been modified outside of the source editor. Do you want to reload it?" for .FCMacro files. So it can likely be done more portably (without pyinotify).