bharadwaj-raju / WeatherDesk

MOVED: https://gitlab.com/bharadwaj-raju/WeatherDesk
https://gitlab.com/bharadwaj-raju/WeatherDesk
GNU General Public License v3.0
217 stars 31 forks source link

Create function main() #16

Closed lexa closed 8 years ago

lexa commented 8 years ago

The purpose of adding main() is to properly handle sys.exit().

sys.exit() throws an exception, which is get caught by try block and has no effect and program continues to work despite lack of necessary files.

bharadwaj-raju commented 8 years ago

Question: Why does sys.exit() throw an exception?

Also, just so you know, the try ... except is to ensure the script won't shut off on temporary network disconnections.

lexa commented 8 years ago

Question: Why does sys.exit() throw an exception?

Because that it is how sys.exit() described in python documentation:

sys.exit([arg]) Exit from Python. This is implemented by raising the SystemExit exception, so cleanup actions specified by finally clauses of try statements are honored, and it is possible to intercept the exit attempt at an outer level.

Also, just so you know, the try ... except is to ensure the script won't shut off on temporary network disconnections.

Don't worry, i preserved try ... except, program won't fail due to temporary network problems. The only change is in handling exit code.

Actually i have a slightly better idea of fixing problem with sys.exit(). I can just move sys.exit() out of the loop.