Skip to content

Instantly share code, notes, and snippets.

@ShinonomeHana
Created November 8, 2018 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShinonomeHana/be8ec0bf77da9503fd2076837d2b8522 to your computer and use it in GitHub Desktop.
Save ShinonomeHana/be8ec0bf77da9503fd2076837d2b8522 to your computer and use it in GitHub Desktop.
from PyQt5.QtWidgets import QApplication,QMainWindow
import sys,threading,time
class MyMainWindow(QMainWindow):
def __init__(self):
super().__init__()
def showMainWindow():
app = QApplication(sys.argv)
main_window = MyMainWindow()
main_window.show()
sys.exit(app.exec_())
thread = threading.Thread(target=showMainWindow)
thread.start()
time.sleep(1999)
@cosven
Copy link

cosven commented Nov 8, 2018

这段代码在 macOS 下运行会直接崩溃

WARNING: QApplication was not created in the main() thread.
2018-11-08 13:54:21.842 Python[31094:2880630] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /BuildRoot/Library/Caches/com.apple.xbs/Sources/Foundation/Foundation-1452.23/Foundation/Misc.subproj/NSUndoManager.m:361
2018-11-08 13:54:21.844 Python[31094:2880630] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread.'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff3795232b __exceptionPreprocess + 171
	1   libobjc.A.dylib                     0x00007fff5efb4c76 objc_exception_throw + 48
	2   CoreFoundation                      0x00007fff379580c2 +[NSException raise:format:arguments:] + 98
	3   Foundation                          0x00007fff39a74340 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
	4   Foundation                          0x00007fff39a02f44 +[NSUndoManager(NSPrivate) _endTopLevelGroupings] + 469
	5   AppKit                              0x00007fff34e5c96e -[NSApplication run] + 997
	6   libqcocoa.dylib                     0x00000001123b35bf qt_plugin_instance + 144175
	7   QtCore                              0x000000010f2d13de _ZN10QEventLoop4execE6QFlagsINS_17ProcessEventsFlagEE + 430
	8   QtCore                              0x000000010f2d6552 _ZN16QCoreApplication4execEv + 130
	9   QtWidgets.so                        0x000000010e1086e0 _ZL23meth_QApplication_exec_P7_objectS0_ + 80
	10  Python                              0x000000010d79be28 _PyMethodDef_RawFastCallKeywords + 243
	11  Python                              0x000000010d79b4af _PyCFunction_FastCallKeywords + 44
	12  Python                              0x000000010d83210e call_function + 467
	13  Python                              0x000000010d829305 _PyEval_EvalFrameDefault + 2604
	14  Python                              0x000000010d79b88e function_code_fastcall + 116
	15  Python                              0x000000010d829c4e _PyEval_EvalFrameDefault + 4981
	16  Python                              0x000000010d79b88e function_code_fastcall + 116
	17  Python                              0x000000010d83217a call_function + 575
	18  Python                              0x000000010d8292ec _PyEval_EvalFrameDefault + 2579
	19  Python                              0x000000010d79b88e function_code_fastcall + 116
	20  Python                              0x000000010d83217a call_function + 575
	21  Python                              0x000000010d8292ec _PyEval_EvalFrameDefault + 2579
	22  Python                              0x000000010d79b88e function_code_fastcall + 116
	23  Python                              0x000000010d79c241 _PyObject_Call_Prepend + 150
	24  Python                              0x000000010d79b5bd PyObject_Call + 136
	25  Python                              0x000000010d897add t_bootstrap + 71
	26  libsystem_pthread.dylib             0x00007fff5fee6661 _pthread_body + 340
	27  libsystem_pthread.dylib             0x00007fff5fee650d _pthread_body + 0
	28  libsystem_pthread.dylib             0x00007fff5fee5bf9 thread_start + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Abort trap: 6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment