Search code examples
pythonpython-3.xmodulepackagereload

Reloading Python Packages


the main module sits within the runner package and executes stuff in the other packages. The main module can also Update the other packages and when that happens I want to reload them in order to get the new functions/modules that were added to those packages.

Project Structure

|--runner
|----main.py
|--core
|----module_1.py
|--configurations
|--utils

But that doesn't work.

I tried the following commands:

  1. importlib.reload - only reloads a single module, using it recursively with sys.modules didn't add the new modules to the import tree. example: if after the update, "core" received a new module "module_new.py" and its imported in "module_1.py" it's not recognized after the reload.
  2. I tried using IPython.lib.deepreload - it didn't work as well.

I've been stuck with this issue for some time, and haven't found any working solution yet. Suggestions? Thanks


Solution

  • I fixed the issue by restarting the entire program using a while loop from an outer execution script. Exit code 2: update required

        Do
        {
            $process = Start-Process python -ArgumentList $CommandLine -verb RunAs -PassThru -WindowStyle Minimized -Wait
        } WHILE ($process.ExitCode -eq 2)