How to make module modification take effect without restarting the application?

Operating system:Win11
Slicer version:5.7.0
Every time I modify the plug code, I need to restart the software for it to take effect. Pressing reload does not work. This is because only restart Slicer can take effect or there are other issues?

Expected behavior:reload and The modified code will take effect
Actual behavior:only restart slicer can take effect

If this is python code, you can enable the developer mode (Edit->Application Settings), and you can reload the module source code, without having to restart the Slicer application.

It does work, so maybe there is something different in your way of using it. A very basic question is whether you have the same folder added to Additional module directories as what you are changing? Because if you built it and you set the qt-scripted-modules folder in the build directory, then it only gets refreshed if you do a build or manually copy the Python file (this is why it would help a lot receiving more details in the report, so that one does not have to guess around). Can you please give details about how you store your module code and what folder did you add to Slicer? Also, can you tell us what appears in the Python window when you press Reload? Thanks!

I don’t have the qt-scripted-modules folder like the other extensions.
Here is the extension path I added to 3D slicer.


When i press reload,the Python window appear:

Maybe there’s something wrong with my add path, but how do I set it up correctly ? Thanks!

I have enabled the developer mode.This more details:
I don’t have the qt-scripted-modules folder like the other extensions.
Here is the extension path I added to 3D slicer.

When i press reload,the Python window appear:

Maybe there’s something wrong with my add path, but how do I set it up correctly ? Thanks!

Thanks for the information! The problem probably will be that you have a lib folder, and the reload function only reloads the module Python file.

So the ‘Reload’ button reloads your Module class, but not the external scripts that your class references. The way around this is to manually reload in your module’s init method.

    def __init__(self, parent=None) -> None:
        """Called when the user opens the module the first time and the widget is initialized."""
        ScriptedLoadableModuleWidget.__init__(self, parent)
        VTKObservationMixin.__init__(self)
        
        import importlib
        import lib
        importlib.reload(lib.dataTransfer)
        importlib.reload(lib.segmentExplorer)