它对我来说很好(OS X 10.7,Python 2.7.1),所以它可能与您的安装有关:
pu@pumbair:~/Downloads$ python test.py
2012-07-05 19:22:19,673 INFO: --------- 1 ---------
2012-07-05 19:22:19,673 INFO: Starting GUI
2012-07-05 19:22:19,674 INFO: Do something alongside guy
2012-07-05 19:22:19,918 INFO: Wait for gui to terminate
2012-07-05 19:22:19,918 INFO: Setup GUI
2012-07-05 19:22:20,422 INFO: Mainloop is over
2012-07-05 19:22:20,424 INFO: thread terminated
2012-07-05 19:22:20,424 INFO: --------- 2 ---------
2012-07-05 19:22:20,425 INFO: Starting GUI
2012-07-05 19:22:20,459 INFO: Do something alongside gui
2012-07-05 19:22:20,459 INFO: Setup GUI
2012-07-05 19:22:20,459 INFO: Wait for gui to terminate
2012-07-05 19:22:20,962 INFO: Mainloop is over
2012-07-05 19:22:20,965 INFO: thread terminated
pu@pumbair:~/Downloads$ python
Python 2.7.1 (r271:86832, Jun 25 2011, 05:09:01)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
但是当然,操作并不总是以相同的顺序执行(与上面的比较):
pu@pumbair:~/Downloads$ python test.py
2012-07-05 19:27:17,827 INFO: --------- 1 ---------
2012-07-05 19:27:17,827 INFO: Starting GUI
2012-07-05 19:27:17,827 INFO: Do something alongside gui
2012-07-05 19:27:17,937 INFO: Setup GUI
2012-07-05 19:27:17,938 INFO: Wait for gui to terminate
2012-07-05 19:27:18,440 INFO: Mainloop is over
2012-07-05 19:27:18,442 INFO: thread terminated
2012-07-05 19:27:18,443 INFO: --------- 2 ---------
2012-07-05 19:27:18,443 INFO: Starting GUI
2012-07-05 19:27:18,478 INFO: Do something alongside gui
2012-07-05 19:27:18,478 INFO: Setup GUI
2012-07-05 19:27:18,479 INFO: Wait for gui to terminate
2012-07-05 19:27:18,981 INFO: Mainloop is over
2012-07-05 19:27:18,982 INFO: thread terminated
在带有 Python 2.6.1 的 10.6.8 上,它也可以工作,但会出现奇怪的消息:
symacbook:Downloads putest$ python test.py
2012-07-05 21:33:49,844 INFO: --------- 1 ---------
2012-07-05 21:33:49,844 INFO: Starting GUI
2012-07-05 21:33:49,844 INFO: Do something alongside gui
2012-07-05 21:33:52,356 INFO: Wait for gui to terminate
2012-07-05 21:33:52,356 INFO: Setup GUI
2012-07-05 21:33:52,858 INFO: Mainloop is over
2012-07-05 21:33:52,859 INFO: thread terminated
2012-07-05 21:33:52,860 INFO: --------- 2 ---------
2012-07-05 21:33:52,860 INFO: Starting GUI
2012-07-05 21:33:52,892 INFO: Setup GUI
2012-07-05 21:33:52,892 INFO: Do something alongside gui
2012-07-05 21:33:52,894 INFO: Wait for gui to terminate
2012-07-05 21:33:52.894 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002d9d90 of class NSCFArray autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.896 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002d51e0 of class NSFont autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.897 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x7fff70737588 of class NSCFString autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.897 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x101233b40 of class _NSThemeCloseWidget autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.898 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002e0ef0 of class NSCFArray autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.898 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002d51e0 of class NSFont autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.899 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x7fff70737588 of class NSCFString autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.899 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002e1170 of class _NSThemeWidget autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.899 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x10120e9c0 of class NSCFArray autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.900 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002d51e0 of class NSFont autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.900 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x7fff70737588 of class NSCFString autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.901 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002e1710 of class _NSThemeWidget autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.901 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002e18e0 of class NSCFArray autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.902 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1012343e0 of class NSTrackingArea autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.902 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x101234010 of class NSTrackingArea autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.903 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002e1910 of class NSView autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.904 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002d3550 of class NSCFArray autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.905 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002e1910 of class NSView autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.905 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x101234840 of class NSCFArray autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.906 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002e1d90 of class NSCFArray autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.906 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x101234870 of class __NSFastEnumerationEnumerator autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.907 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x101233b40 of class _NSThemeCloseWidget autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.907 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x101233b40 of class _NSThemeCloseWidget autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.908 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002e1710 of class _NSThemeWidget autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.908 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002e1710 of class _NSThemeWidget autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.908 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002e1170 of class _NSThemeWidget autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.909 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002e1170 of class _NSThemeWidget autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.909 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002e22e0 of class NSTrackingArea autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.910 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002e24d0 of class NSConcreteAttributedString autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.911 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x7fff70737588 of class NSCFString autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.911 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002d51e0 of class NSFont autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.911 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002d91f0 of class NSFont autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.912 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x7fff70737588 of class NSCFString autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.912 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002e28b0 of class NSTrackingArea autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.913 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002e3ab0 of class NSConcreteMapTable autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.914 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002e3e30 of class NSCFArray autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.915 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002e1dc0 of class NSObject autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.915 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002e4120 of class NSCFArray autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.916 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x101234a60 of class NSMenuItem autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.916 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002ac2e0 of class NSCFNumber autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.916 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002e4180 of class NSCFDictionary autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.917 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x10120e770 of class NSCFNumber autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.917 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1012031d0 of class NSCFDictionary autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.918 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x101233b40 of class _NSThemeCloseWidget autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.919 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x101233b40 of class _NSThemeCloseWidget autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.919 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002e1710 of class _NSThemeWidget autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.919 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002e1710 of class _NSThemeWidget autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.920 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002e1170 of class _NSThemeWidget autoreleased with no pool in place - just leaking
2012-07-05 21:33:52.920 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002e1170 of class _NSThemeWidget autoreleased with no pool in place - just leaking
2012-07-05 21:33:53.393 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x101236910 of class NSCFArray autoreleased with no pool in place - just leaking
2012-07-05 21:33:53.393 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x10120e770 of class NSCFNumber autoreleased with no pool in place - just leaking
2012-07-05 21:33:53.394 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x101236ce0 of class NSCFDictionary autoreleased with no pool in place - just leaking
2012-07-05 21:33:53.394 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002e24b0 of class NSCFString autoreleased with no pool in place - just leaking
2012-07-05 21:33:53.395 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x1002ac2e0 of class NSCFNumber autoreleased with no pool in place - just leaking
2012-07-05 21:33:53.395 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x101236d20 of class NSCFDictionary autoreleased with no pool in place - just leaking
2012-07-05 21:33:53.396 Python[1281:3407] *** __NSAutoreleaseNoPool(): Object 0x101236e70 of class NSCFArray autoreleased with no pool in place - just leaking
2012-07-05 21:33:53,398 INFO: Mainloop is over
2012-07-05 21:33:53,400 INFO: thread terminated