尝试同时运行两个函数时断言失败和NSInternalInconsistencyException

时间:2017-08-04 21:47:08

标签: python multithreading python-multithreading

我有两个我想同时运行的函数 - show_video()和gesture_control()。第一个从相机流中读取图像并使用matplotlib绘制它们。第二个连接几个API,以便根据视频流中检测到的对象触发某些事件。我在教程中看到我可以同时运行两个函数,如下所示:

if __name__ == '__main__':
    Thread(target = show_video).start()
    Thread(target = gesture_control).start()

但我得到了各种各样的错误......

2017-08-04 14:39:05.072 python[9512:693356] WARNING: nextEventMatchingMask should only be called from the Main Thread! This will throw an exception in the future.
2017-08-04 14:39:05.072 python[9512:693356] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /Library/Caches/com.apple.xbs/Sources/Foundation/Foundation-1349.25/Misc.subproj/NSUndoManager.m:363
2017-08-04 14:39:05.075 python[9512:693356] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /Library/Caches/com.apple.xbs/Sources/Foundation/Foundation-1349.25/Misc.subproj/NSUndoManager.m:363
2017-08-04 14:39:05.077 python[9512:693356] *** 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                      0x00007fffa45580db __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x00007fffb91dfa2a objc_exception_throw + 48
    2   CoreFoundation                      0x00007fffa455cc32 +[NSException raise:format:arguments:] + 98
    3   Foundation                          0x00007fffa5fc5d50 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
    4   Foundation                          0x00007fffa5f503f3 +[NSUndoManager(NSPrivate) _endTopLevelGroupings] + 170
    5   AppKit                              0x00007fffa1ff4047 -[NSApplication run] + 1200
+50 more rows

libc++abi.dylib: terminating with uncaught exception of type NSException

0 个答案:

没有答案
相关问题