My script ends with sys.exit(0) but PyCharms says 'Process finished with exit code -1'

I have a Python script:

def main() -> int:

# do something
    return 0


if __name__ == '__main__':
sys.exit(main())

but in the Console window, when the script ends, it says:

Process finished with exit code -1

Am I doing something wrong?

2 comments
Comment actions Permalink

This example exits with code 0 for me as expected:

import sys


def main() -> int:
# do something
return 0


if __name__ == '__main__':
sys.exit(main())

 

Please try running it from the terminal without using IDE.

0
Comment actions Permalink

OK, I lied :-). My actual script is very long and complicated and performs some multi-threading, but the MT activity ends before the code reaches the 'return 0' statement.

To summarize:

1. My actual script, when run in the command line (no IDE), returns 0, as expected.

2. In the IDE, it shows -2, as I reported.

3. The brain-dead example that I provided returns 0 inside and outside of the IDE, so it's not helpful. Sigh.

0

Please sign in to leave a comment.