Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using sys.exit() with app.exec_ in pyqt

Tags:

python

pyqt

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.

like image 671
user3616508 Avatar asked Aug 01 '14 08:08

user3616508


People also ask

What does app exec _() do?

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.


1 Answers

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.

like image 192
Alex P Avatar answered Sep 18 '22 14:09

Alex P