我想在背景线程中从Ipython设置Pygame应用程序。
在将其他任何地方导入该线程之前,我已经尝试从该线程导入pygame。
问题是,当我在此线程内启动主循环时,很快就会冷冻,直到我按Enter在解释器中为止。
我怎么能始终保持它的运行?
注意:当启动仅打印东西的虚拟线程时,它不会被阻止,因此我认为它与Pygame更相关,而不是与Ipython或Python解释器。同样的行为出现在ipython和常规python解释器中
I would like to setup a pygame app from ipython in a background thread.
I already tried to import pygame from this thread before importing it anywhere else.
The problem is that when I launch my main loop inside this thread, soon, it gets frozen until I press enter in the interpreter.
How could I always keep it running ?
Note : that when starting a dummy thread that just print stuffs, it doesn't get blocked, so I think it's more related to pygame than to ipython or python interpreter. The same behaviour appears in IPython and regular python interpreter
发布评论
评论(1)
我刚刚为我自己的项目构建了一个示例!
我不确定是什么导致你的冻结,尽管我知道操作系统一直试图强制它关闭,直到我开始实际处理事件队列中的事件 - 显然,当队列填满时,操作系统认为我的线程已损坏。
这是下面的基本想法,尽管您可以找到我的稍微更详细的示例,其中包含更多注释和要使用的示例实例,在 GitHub 上。
I just built an example of this for my own project!
I'm not sure what caused yours to freeze, though I know for mine the OS kept trying to force it to close until I started actually processing the events from the event queue - apparently when the queue filled up the OS thought my thread was broken.
Here's the basic idea below, though you can find my slightly more detailed example, with more comments and with example instances to use, Here on GitHub.