[Python] How to quietly exit a runfile script?

Discussão em 'Python' iniciado por Stack, Abril 30, 2025.

  1. Stack

    Stack Membro Participativo

    I am using Spyder 6 console to invoke a Python script via the runfile command. After a recent Anaconda update, I found that sys.exit() no longer exits the script quietly. It prints:

    An exception has occurred, use %tb to see the full traceback.

    SystemExit: 0

    C:\Users\User.Name\AppData\Local\anaconda3\envs\py39\lib\site-packages\IPython\core\interactiveshell.py:3534: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
    warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)


    Using exit() and quit() are equally verbose.

    I came across suggestions to use sys.exit(0), but it doesn't change anything for me. I want to avoid os._exit() because it skips cleanup handlers.

    How would I gracefully and quietly exit a script that is called with runfile?

    Continue reading...

Compartilhe esta Página