I recently took up GUI programming in PySide and I'm having trouble with an oddity regarding exit commands. Sys.exit([x])
seems to be widely used to stop a PySide program; whenever I use it in a PySide program using classes, however, it doesn't return an exit code to PyCharm or stop the Python process in the task manager.
Oddly enough it seems it's incredibly hard to do either of these things when using PySide; I could break out of the main loop, call sys.exit(0)
, raise SystemExit(0)
and it wouldn't stop running in the background. This only happens when using PySide, and only when using classes to construct widgets.
I have tried all sorts of combinations, but the only way I can reliably kill the process is by using os._exit(0)
, which is a bit brutal. Bizzarely it seems I am one of very few people that encounter this issue, and I'm very curious as to what's causing it.
I verified this wasn't a bug in my code per se by running a Pyside tutorial script using sys.exit(app.exec_())
from Zetcode. Again, calling sys.exit()
did not return an exit value or kill the Python process. As it's a tutorial I am assuming that, for most people, this code works just fine. Could this be a version issue (I use Python 3.4 and PySide 1.2.2)?
EDIT; I also found out it doesn't matter where I place the sys.exit(0) command, provided it's after my class definitions. Imports > sys.exit() > class just instantly quits (as one would expect), but Imports > class > sys.exit() - even if I haven't actually called on any classes yet - does not properly shut down the program.