1

I wanted to write a PyQt app that would spawn its window in a separate thread so I could mess with its data structures in an interactive shell while it's running. Unfortunately, an attempt to do exit() inside the shell does not kill the application, probably because the Qt thread is still running. How do I force the Python shell to die once I pressed CTR+D or typed exit() or typed exit in the console? Here is the testcase:

#!/usr/bin/python -i

from PyQt4 import QtGui

class MainWindow(QtGui.QMainWindow):
    pass

def main():
    import sys

    app = QtGui.QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec_())


if __name__ == '__main__':
    import threading
    threading.Thread(None, main).start()
d33tah
  • 10,999
  • 13
  • 68
  • 158
  • threading module does not offer any kill-method. this might help http://stackoverflow.com/questions/323972/is-there-any-way-to-kill-a-thread-in-python – theAlse Mar 17 '13 at 20:41
  • The trick would be to make main thread handle the exit so that instead of waiting for the remaining threads, it would call app.close(). – d33tah Mar 17 '13 at 20:43

0 Answers0