- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 multiprocessor.Pool
并行处理一些文件。该代码等待接收文件,然后使用 Pool.apply_async
将该文件发送给工作人员。 ,然后处理文件。
这段代码应该一直在运行,因此我从不关闭池。然而,这会导致池随着时间的推移消耗大量内存。
代码是这样的:
if __name__ == "__main__":
with Pool(processes=PROCESS_COUNT) as pool:
while True:
f = wait_for_file()
pool.apply_async(process_file, (f,))
如何在不关闭池的情况下防止发生高内存使用率?
最佳答案
是的,如果你分配资源并且你不释放它们,不管是 spawned processes 的数量或者只是(一大块)内存,在您或您的系统自愿或强制解除分配之前,您机器上用于其他任务的资源将减少。
您可能想使用 maxtasksperchild
Pool
的论据试图杀死奴隶,例如如果他们分配了内存并且您在某处发生了泄漏,那么您至少可以节省一些资源。
Note: Worker processes within a Pool typically live for the complete duration of the Pool’s work queue. A frequent pattern found in other systems (such as Apache, mod_wsgi, etc) to free resources held by workers is to allow a worker within a pool to complete only a set amount of work before being exiting, being cleaned up and a new process spawned to replace the old one. The maxtasksperchild argument to the Pool exposes this ability to the end user.
Pool
实现因为在你到达那里之前,它会是马车,你会不必要地浪费时间。
相反 使用例如
Celery (
tutorial ) 甚至希望对讨厌的极端情况进行测试,您可能会花费比必要的更多时间。
关于python - 不断运行的 worker 池,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68411908/
如果这不是一个错误,那就是另一个错误。如果不是那样的话,那就是别的东西了。我觉得我的项目已经改变了很多,现在只是试图解决代码签名问题,结果一切都搞砸了。我严格按照说明进行操作,但出现错误,例如当前的“
我不确定是否有一些我不知道的内置变量或规则,或者 make 是否有问题,或者我只是疯了。 对于我的一个项目,我有一个如下的 makefile: CC=g++ CFLAGS=-O3 `libpng-co
我有大约 10 个 div,它们必须不断翻转,每个 div 延迟 3 秒 这个 codrops 链接的最后一个效果是我正在寻找的,但无需单击 div http://tympanus.net/Devel
我如何使用 jQuery 持续运行 PHP 脚本并每秒获取响应,以及将鼠标上的少量数据发送到同一脚本? 我真的必须添加一些随机扩展才能让这么简单的计时器工作吗? 最佳答案 To iterate is
JBoss 4.x EJB 3.0 我见过如下代码(大大简化): @Stateless @TransactionAttribute(TransactionAttributeType.NOT_SUPPO
使用 PHPStorm,我试图忽略每次尝试进行 git 提交时 pop 的 workspace.xml。 我的 .gitignore 看起来像: /.idea/ .idea/workspace.xml
我是一名优秀的程序员,十分优秀!