[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Is there any reason to call sys.exit() to close a pygame program?



On Sun, Aug 13, 2017 at 2:29 AM, Sam Bull <sam.hacking@xxxxxxxx> wrote:
On sab, 2017-08-12 at 18:23 +0000, skorpio wrote:
> I usually quit pygame by breaking out of the main loop and calling
> pygame.quit() followed by sys.exit(), but I can't remember anymore
> where I learned to use sys.exit and why it should be used. 

​For a while (Python 2.3, 2.4) I vaguely remember `sys.exit(...)` was also useful for killing dangling PyGame windows that would persist after exceptional program termination when debugging in IDLE (i.e., put your whole program in `try`/`except`, and put `sys.exit(...)` in the `except`). This may have been where the original suggestion to use it comes from. However, that usage no longer seems to be required.
​
 
If you need to use an exit function, then I've found using the built-in
exit() function gives an error if you use pyinstaller to create a
frozen binary. That's the only reason I try to use sys.exit(). I've not
had any problems just allowing the execution to reach the end of the
file and completing naturally though.

​AFAIK the only current advantage of using one of the exit calls in Python is to be able to supply an exit code to the parent process. In C++, I typically return the code from `main(int,char*[])` instead because it's clearer OO encapsulation, but this isn't possible in Python.

Ian​