后续:Python仿真软件的多处理或多线程
这是此的后续内容。 (您不必阅读所有答案,只需阅读问题)
人们向我解释了进程和线程之间的区别。 一方面,我想要进程,这样我就可以充分利用 CPU 的所有核心,另一方面,在进程之间传递信息不太理想,而且我不想拥有我正在处理的巨大对象的两个副本和。
所以我一直在想一种方法来做到这一点,将进程和线程结合起来; 告诉我这是否有意义。 我的程序中的主要进程是GUI进程。 我将让它产生一个“渲染管理器”线程。 渲染管理器线程将负责渲染模拟,但是,它不会自行渲染它们,而是生成其他进程来为其完成工作。
这些是目标:
- 渲染应该利用所有可用的核心。
- GUI 永远不应该变得迟缓。
我希望渲染管理器成为一个线程的原因是它必须与 GUI 共享大量信息:即模拟时间线。
那么你认为这是一个好的设计吗? 您有什么改进建议吗?
更新:
抱歉,我对“渲染”一词的使用令人困惑。 我所说的渲染是指计算模拟,而不是在屏幕上渲染它。
this is a follow up to this. (You don't have to read all the answers, just the question)
People explained to me the difference between processes and threads. On the one hand, I wanted processes so I could fully exploit all core of the CPU, on the other hand, passing information between processes was less than ideal, and I didn't want to have two copies of the huge object I was dealing with.
So I've been thinking about a way to do this, combining processes and threads; tell me if this makes sense. The main process in my program is the GUI process. I will have it spawn a "rendering-manager" thread. The rendering-manager thread will be responsible for rendering the simulation, however, it will not render them by itself, but spawn other processes to do the work for it.
These are the goals:
- Rendering should take advantage of all the cores available.
- The GUI should never become sluggish.
The reason I want the rendering-manager to be a thread is because it has to share a lot of information with the GUI: Namely, the simulation-timeline.
So do you think this is a good design? Do you have any suggestions for improvement?
Update:
Sorry for my confusing use of the word "render". By render I mean calculate the simulation, not render it on screen.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在使用进程之前,请确保:
在我看来,一个好的经验法则是:
所以我建议首先“简单地”使用线程。 也许您会意识到,即使使用一个线程来计算模拟,它也足够快。
Before using processes, make sure that:
In my opinion a good rule of thumb is:
So I'd suggest to “simply” use threads first. Maybe you will realize that even with one thread computing the simulation it's fast enough.
我不是图形技术方面的专家,但这听起来很像 GPU 的用途。 也许 pygame 更符合您的需求?
I'm no expert on graphics technologies, but this sounds a lot like what GPUs are intended for. Perhaps pygame is more what you're looking for?