如何解决Mac OS X Pynput问题:`NSInternalInconsistencyException`
我正在Mac OS Catalina设备上使用Pynput。我正在以管理员身份运行pynput
脚本。
有效的代码:
import threading
from skimage.viewer import ImageViewer
from skimage import io
def view(fname):
""" View a Skimage Image """
print(threading.current_thread().name) # make sure it's running in the main thread
img = io.imread(fname)
viewer = ImageViewer(img)
viewer.show()
view('board_shot.png')
以上内容的输出将打印:
MainThread
,然后使用ImageViewer
我的无效代码:
import threading
from skimage.viewer import ImageViewer
from skimage import io
from pynput.keyboard import Listener
def main():
with Listener(on_release=checkKeyRelease) as listener:
listener.join() # keep on listening
view('board_shot.png') # view after press
def view(fname):
""" View a Skimage Image """
print(threading.current_thread().name) # make sure it's running in the main thread
img = io.imread(fname)
viewer = ImageViewer(img)
viewer.show()
def checkKeyRelease(key):
if 'char' in dir(key):
if key.char == 's':
return False # stop listener
main()
输出
MainThread
2020-08-18 08:10:28.965 python[23022:1182855] pid(23022)/euid(501) is calling TIS/TSM in non-main thread environment,ERROR : This is NOT allowed. Please call TIS/TSM in main thread!!!
2020-08-18 08:10:28.965 python[23022:1182855] pid(23022)/euid(501) is calling TIS/TSM in non-main thread environment,ERROR : This is NOT allowed. Please call TIS/TSM in main thread!!!
2020-08-18 08:10:28.965 pyt ... *** Assertion failure in void assertRunningOnAppKitThread(void)(),/BuildRoot/Library/Caches/com.apple.xbs/Sources/ViewBridge/ViewBridge-401.1/ViewBridgeUtilities.m:912
2020-08-18 08:10:29.542 python[23022:1182855] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException',reason: 'not running on AppKit (main) thread'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff39847a7d __exceptionPreprocess + 256
1 libobjc.A.dylib 0x00007fff63f19a17 objc_exception_throw + 48
2 CoreFoundation 0x00007fff39862796 +[NSException raise:format:arguments:] + 98
3 Foundation 0x00007fff3bb50cf5 -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 166
4 ViewBridge 0x00007fff61243c37 __26+[NSRemoteView initialize]_block_invoke + 15
5 libdispatch.dylib 0x00007fff656995f8 _dispatch_call_block_and_release + 12
6 libdispatch.dylib 0x00007fff6569a63d _dispatch_client_callout + 8
7 libdispatch.dylib 0x00007fff656a568d _dispatch_main_queue_callback_4CF + 1135
8 CoreFoundation 0x00007fff39791a37 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
9 CoreFoundation 0x00007fff39791161 __CFRunLoopRun + 2289
10 CoreFoundation 0x00007fff3979061e CFRunLoopRunSpecific + 455
11 HIToolbox 0x00007fff389ef1ab RunCurrentEventLoopInMode + 292
12 HIToolbox 0x00007fff389eeee5 ReceiveNextEventCommon + 603
13 HIToolbox 0x00007fff389eec76 _BlockUntilNextEventMatchingListInModeWithFilter + 64
14 AppKit 0x00007fff36d8777d _DPSNextEvent + 1135
15 AppKit 0x00007fff36d8646b -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1361
16 AppKit 0x00007fff36d80588 -[NSApplication run] + 699
17 libqcocoa.dylib 0x0000001a1d49e15b qt_plugin_instance + 99558
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Abort trap: 6
正如您在上方看到的那样,该图像实际上是在主线程中查看的,所以我不明白问题出在哪里。有人知道吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。