Can anyone explain the relative merits of using sys.exit(app.exec_())
rather than the simpler app.exec_()
to start a GUI in PyQt?
I am new to PyQt and have seen both examples.
app. exec_() does not lock anything, it runs a GUI event loop that waits for user actions (events) and dispatches them to the right widget for handling.
When Unix-style applications exit, they return a number to their parent process called a 'status code' or 'exit status'. 0
is used to indicate success; anything non-zero is a failure. (There's been some attempt to standardise the meaning of error codes, but it's still generally left up to each program.)
app.exec_()
runs your main loop, and returns a status code when it exits. sys.exit(n)
quits your application and returns n
to the parent process (normally your shell). So the difference is, the longer version passes on the status code when your program exits. It's better to use sys.exit(app.exec_())
because then other parts of the system can detect when your program exited due to an error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With