Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception has occurred: SystemExit 3 #253

Open
filipre opened this issue Jun 6, 2023 · 6 comments
Open

Exception has occurred: SystemExit 3 #253

filipre opened this issue Jun 6, 2023 · 6 comments
Labels
P3 question Further information is requested

Comments

@filipre
Copy link

filipre commented Jun 6, 2023

Hi!

Sometimes (see below), I get the following exception when I run the functions framework in the VS Code debugger after detecting a code change.

Uncaught Exception

Exception has occurred: SystemExit
3
  File "/Users/rene/.vscode/extensions/ms-python.python-2023.9.11461009/pythonFiles/lib/python/debugpy/server/cli.py", line 314, in run_module
    run_module_as_main(options.target, alter_argv=True)
  File "/Users/rene/.vscode/extensions/ms-python.python-2023.9.11461009/pythonFiles/lib/python/debugpy/server/cli.py", line 429, in main
    log.reraise_exception(
  File "/Users/rene/.vscode/extensions/ms-python.python-2023.9.11461009/pythonFiles/lib/python/debugpy/server/cli.py", line 429, in main
    log.reraise_exception(
  File "/Users/rene/.vscode/extensions/ms-python.python-2023.9.11461009/pythonFiles/lib/python/debugpy/__main__.py", line 39, in <module>
    cli.main()
SystemExit: 3

The exception is only thrown "sometimes" but when it's thrown, it happens multiple times in a row for each "change" or whenever I save a file. I do not see a pattern when it is thrown and when not. Do you have an idea where this could be coming from and why it only happens sometimes? I first thought it is related to broken code, but that does not seem to be the case.

VS Code Terminal

 * Tip: There are .env or .flaskenv files present. Do "pip install python-dotenv" to use them.
 * Serving Flask app '********'
 * Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on all addresses (0.0.0.0)
 * Running on http://127.0.0.1:8082
 * Running on http://***.***.***.***:8082
Press CTRL+C to quit
 * Restarting with watchdog (fsevents)
 * Tip: There are .env or .flaskenv files present. Do "pip install python-dotenv" to use them.
 * Debugger is active!
 * Debugger PIN: ***-***-***
 * Detected change in '/Users/rene/Development/*****.py', reloading

launch.json file:

{
    "name": "▶ Service",
    "type": "python",
    "request": "launch",
    "module": "functions_framework",
    "args": ["--target",  "service", "--debug", "--port=8082"],
    "cwd": "${workspaceFolder}"
}, 

Version

functions-framework==3.3.0
$ python -V
Python 3.11.2

I'm happy about any pointer to the right direction!

@filipre
Copy link
Author

filipre commented Jun 6, 2023

Possibly related, but the exception is different and the error happens every time, regardless if it is a syntax error or not: #213

@KaylaNguyen
Copy link
Contributor

Hi @filipre, this seems to be a VS Code issue: https://stackoverflow.com/q/52372810. It's not related to #213.
Can you try the workaround suggested and see if that works for you?

@filipre
Copy link
Author

filipre commented Jun 7, 2023

Thank you for your reply. The Stackoverflow thread shifts the question to "Why does the CLI debugger finishes with the exit code 3"? VS Code will always throw an exception, when python finishes with an error code. I think that's the correct behavior. For example, this code should not throw an exception

sys_exit(0)

But this one should

sys_exit(1)

I could disable "Uncaught Exceptions" but I do not want this because I would also ignore exceptions in my program code.

The exact line that causes the system exit 3 is

run_module_as_main(options.target, alter_argv=True)

and options.target is 'functions_framework'. The method is defined (?) in runpy somewhere. The sys.path looks correct, too and refers to the right virtual env packages and custom packages.

Is there something else I could provide to figure out the root of the problem?

@filipre
Copy link
Author

filipre commented Jun 7, 2023

I created https://github.com/filipre/vscode-debugger-exit-3-bug to debug the issue

Here are some observations:

  • I think run_module_as_main always exits with error code 3 and not just sometimes.
  • If I uncheck "Raised Exception", "Uncaught Exception" and "User Uncaught Exception", the debugger restarts without raising an exception
  • If I then check "User Uncaught Exceptions", I can restart the debugger once but not twice or more times
  • If I check "Uncaught Exceptions", it always raises an exception.

Maybe after changing a file, system_frameworks does not "properly" stop the debugger and causes the exit code?

@HKWinterhalter HKWinterhalter added question Further information is requested P3 labels Sep 6, 2023
@fswair
Copy link

fswair commented Mar 22, 2024

this error all about library's trigger method.

there is a default "trigger_reload" method and it raises SystemExit when file has been changed.

def trigger_reload(self, filename: str) -> None: self.log_reload(filename) sys.exit(3) # just make it disable in source code

or

`def your_trigger_method(fn): pass

reloader.trigger_reload = your_trigger_method`

@filipre
Copy link
Author

filipre commented Apr 3, 2024

this error all about library's trigger method.

Which library do you mean? functions-framework or something else?

@HKWinterhalter HKWinterhalter removed their assignment May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants