Algis Kabaila  wrote:
> On Sunday 02 January 2011 02:03:10 anatoly techtonik wrote:
> > On Sat, Jan 1, 2011 at 8:12 AM, Algis Kabaila
>  wrote:
> > > What is the reason for using sys.exit(main()) when simple
> > > and clear main() would do just as well?
> >
> > Return exit code to the system?
> > --
> > anatoly t.
>
> I guess that may well be so, but is it really necessary? My question
> comes from the fact that a simpler form is used in my favourite text
> book on PyQt, a book that arguably every aspiring PyQt or PySide
> programmer could be expected to read.
>
> So why is sys.exit(app.exec_()) more attractive to so many people then
> simpler app.exec_() ? After all, it is not the failure that we are
> interested in, but a functioning program, no? And how would sys.exit
> help(app.exec_()) help us in case of sys.exit() being invoked by a
> program bug?
>
> Whilst I feel happy to follow my favourite book and author and use
> app.exec_() to invoke the event loop, I do not want to mislead other
> newbies if sys.exit(app.exec_()) is really superior.
> Is it?
>
> Thanks a lot for partly answering this question.. I would like to see a
> deeper look into it. Be assured that the quesion is not being asked
> frivolously.

If the application quits with QApplication.exit(), then sys.exit() is necessary 
to pass the error code back to the system. Of course if you're absolutely sure 
that QApplication.exit() will never be called (at least not with a non-zero 
code), you can avoid sys.exit().

It's true that passing error codes to the system is less critical for a GUI 
application than for a command-line application, but if you do have an 
unexpected failure that forces the application to exit it's a very good idea to 
communicate that to the system so that the program that launched your 
application can act appropriately if needed.

So I wouldn't recommend dropping sys.exit().


Cheers,
Farsmo
                                          
_______________________________________________
PySide mailing list
[email protected]
http://lists.openbossa.org/listinfo/pyside

Reply via email to