多处理|抓住一个正在退出的口译员
我正在研究一个进化计算问题,我正在使用出色的 ECSPY 模块来实现该问题。 我使用的适应度值来自相当复杂的动力学模拟。 问题是我不喜欢让我的模拟防弹的方法;它毫无用处,因为进化过程可能会出现 simu 引擎无法解决的情况。然而,限制生成器返回可解的场景是过度限制的。
所以我的方法很简单;如果模拟时间太长,或者崩溃,那么,我会让达尔文的仁慈来处理它。
我正在使用多处理模块来评估候选人的适合度。 如何在给定的秒数内捕获段错误解释器或杀死它?
预先非常感谢,
-jf
I'm working on an evolutionary computing problem, which I'm implementing with the excellent ECSPY module.
The fitness value I'm using is derived from a pretty complex dynamics simulation.
Thing is that I do not like the approach of making my simulation bomb-proof; its pretty useless since the evolutionary process could come up with situations that the simu engine just is not built to be able to solve. However, constraining the generator to return scenes that are solvable is over constraining things.
So my approach is simple; if the simulation takes too long, or crashes, well, I'll just let Darwin's mercy handle it.
I'm using the multiprocessing module to evaluate the fitness of the candidates.
How do I catch a segfaulting interpreter or kill it given a number of seconds?
Many thanks in advance,
-jf
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
subprocess
将 Python 解释器“包装”在 Python 脚本中。启动一个运行您的事物的 Python 解释器。
启动时钟。
等待时钟耗尽或子进程崩溃。
执行此操作的简单而懒惰的方法是定期轮询子进程以查看它是否已死亡。是的,它是“忙等待”,但如果您不希望子进程完成时立即收到通知,那么它实现起来很简单,而且资源成本相对较低。
类似的事情可能会成功。如果恰好在超时间隔处退出,则存在竞争条件;杀戮可能会失败。
Use
subprocess
to "wrap" a Python interpreter inside a Python script.Start a Python interpreter that runs your thing.
Start a clock.
Wait until the clock runs out or the child process crashes.
The easy, lazy way to do this is to poll the subprocess periodically to see if it's dead yet. Yes, it's "busy waiting", but it's simple to implement and relatively low resource cost if you don't want instant notification when the subprocess finishes.
Something like that might work out. It has a race condition if it happens to exit right at the timeout interval; the kill could fail.