What is the difference between multiprocessing and subprocess?

前端 未结 3 489
闹比i
闹比i 2020-12-07 11:03

My work should use parallel techniques, and I a new user of python. So I wonder if you could share some material about the python multiprocessing and subp

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-07 11:23

    Subprocess spawns new processes, but aside from stdin/stdout and whatever other APIs the other program may implement you have no means to communicate with them. Its main purpose is to launch processes that are completely separate from your own program.

    Multiprocessing also spawns new processes, but they run your code, and are designed to communicate with each other. You use it to divide tasks within your own program across multiple CPU cores.

提交回复
热议问题