2024-W12 为什么你的多进程池卡住了

为什么你的多进程池卡住了

Mar 18, 2024
周刊, Python

图为北京陶然亭公园(库存)

之前组内遇到的一个问题,在多进程池中并行运行的任务,有一定几率会全部卡住,问题的原因是 Python 的 logging 模块在单进程下虽然是线程安全的,但是在多进程并行模型下,多个任务同时写同一 log 文件处理不好就可能会有死锁问题,主要原因就是在 fork() 时,子进程复制了父进程的所有(除了父进程本身),这其中就包含了一个可能正是未被释放的锁。下面是两条可参考的资料:

Why your multiprocessing Pool is stuck
https://pythonspeed.com/articles/python-multiprocessing/

Python Logging Cookbook: Logging to a single file from multiple processes
https://docs.python.org/3/howto/logging-cookbook.html#logging-to-a-single-file-from-multiple-processes

另外,本周天气转暖,我也开始了和球友中午去练习🏓了。

发现 #

翁天信的博客:最后一篇博文
https://blog.dandyweng.com/2023/11/the-last-post/

一位阿里程序员的博客
https://vra.github.io/

阮一峰写的《TypeScript 教程》
https://wangdoc.com/typescript/

Python3 源码剖析
https://fasionchan.com/python-source/

解决 .git 目录过大问题
https://www.escapelife.site/posts/b400b7f8.html

独立:中国独立 iOS 和 macOS 开发者图鉴
https://josephchang10.github.io/chinese-indie-hackers/

LibHunt: Discover trending open-source projects and their alternatives
https://www.libhunt.com/

Last Modified at Mar 30, 2024