[英]Is there a workaround to empty event queue in separate thread?
I used a separate thread to call pygame.event.get()
for ages on Ubuntu without any problem.我使用一个单独的线程在 Ubuntu 上调用
pygame.event.get()
没有任何问题。 However MacOS throws an exception 'NSInternalInconsistencyException', reason: 'nextEventMatchingMask should only be called from the Main Thread!'
然而,MacOS 会抛出异常
'NSInternalInconsistencyException', reason: 'nextEventMatchingMask should only be called from the Main Thread!'
; ; and Windows reports the window to be
(Not answering)
after a few seconds of normal execution, which I assume to have the same explanation, meaning that Linux is tolerant to this software design unlike other OSes.并且 Windows 在正常执行几秒钟后报告窗口为
(Not answering)
,我认为这有相同的解释,这意味着与其他操作系统不同,Linux 可以容忍这种软件设计。
Is there any workaround to keep emptying the event queue in a separate thread, or does it basically mean that pygame 1.9.1 on python 2.7 cannot work that way at all?是否有任何解决方法可以在单独的线程中保持清空事件队列,或者这是否基本上意味着 python 2.7 上的 pygame 1.9.1 根本无法以这种方式工作?
I know GUI events are usually handled in main thread, but my Python lib is intended to be used with ipython.我知道 GUI 事件通常在主线程中处理,但我的 Python 库旨在与 ipython 一起使用。 By design, the main thread, ie the user's ipython cells might be executing no operation or CPU-greedy loops, thus it can't take care of
pygame.event.get()
.根据设计,主线程,即用户的 ipython 单元可能不执行任何操作或 CPU 贪婪循环,因此它无法处理
pygame.event.get()
。
It is only possible to post events from other thread, but the event queue has to be handled in the main thread.只能从其他线程发布事件,但事件队列必须在主线程中处理。 See the documentation of
pygame.event
:请参阅
pygame.event
的文档:
[...] The event subsystem should be called from the main thread.
[...] 事件子系统应该从主线程调用。 [...]
[...]
However, if you read on但是,如果您继续阅读
[...] If you want to post events into the queue from other threads, please use the
pygame.fasteventpygame
module for interacting with events and queues module.[...] 如果您想从其他线程将事件发布到队列中,请使用
pygame.fasteventpygame
模块与事件和队列模块进行交互。 [...][...]
See pygame.fastevent
module:参见
pygame.fastevent
模块:
pygame.fastevent
is a wrapper for Bob Pendleton's fastevent library.pygame.fastevent
是 Bob Pendleton 的fastevent库的包装器。 It provides fast events for use in multithreaded environments.它提供了用于多线程环境的快速事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.