multiprocessing returns “too many open files” but using `with…as` fixes it. Why?

后端 未结 3 2057
误落风尘
误落风尘 2021-02-05 05:31

I was using this answer in order to run parallel commands with multiprocessing in Python on a Linux box.

My code did something like:

import multiproce         


        
3条回答
  •  有刺的猬
    2021-02-05 06:10

    It is context manger. Using with ensures that you are opening and closing files properly. To understand this in detail, I'd recommend this article https://jeffknupp.com/blog/2016/03/07/python-with-context-managers/

提交回复
热议问题