How do I name the processes in a multiprocessing.pool?
如果我创建一个包含4个worker的池并将它们设置为执行一些任务(使用pool.apply_async(..)
),那么我可以使用multiprocessing.current_process().name
从内部访问每个进程的multiprocessing.current_process().name
,但是如何设置来自父进程的名称(这主要是用于日志记录)?
Process.name
is just a setter, you can freely assign to it.
The Pool takes an initializer
argument. This can be any callable, and it'll be called once when each subprocess starts up. You can point this to a function that sets the name
property of that process to whatever you want.
上一篇: Mongoose不会创建TTL索引