Search code examples
pythonerror-handlinghttprequestsys.path

Exception handling from main script in python


I have a program in python. There are several python scripts which I am calling from the main script. The other scripts are also calling other scripts. But all that process begins in the main script.

every function is seperated in different files, they are imported with sys.path.append() & from aFolder import aFunction .

This is an example with the call stack.

-mainScript
   -Calls childScriptX()
       -Calls childScriptY()
       -Calls childScriptZ()
       -Calls ...
   -Calls childScriptK()

Somewhere in this calls, Errors occurs. But they cannot be caught from the mainScript. I tried wrapping the whole mainScript with Try-Except but that seems not working.

I imagine that when an error happens inside of the child functions, the exception does not pass to the parent, hence Error not caught, and breaking the program..

Every time the program breaks, I am just restarting manually, that's the behaviour I would want but only to do it automatically. The errors that occurs are HTTP requests errors that I know a priori that will keep happening. But I don't want to catch them in the child but in the parent..

#That's the structure I have right now

-mainScript.py

while True:
    try:
        childScriptX()
        childScriptZ()
        ...
    except:
        ...

Any suggestions ?


Solution

  • It seems jupyter-lab was causing the crash. I just run the script through the console and it runs fine 10 days now.