deciding among subprocess, multiprocessing, and thread in Python?

后端 未结 5 848
感情败类
感情败类 2020-11-29 15:10

I\'d like to parallelize my Python program so that it can make use of multiple processors on the machine that it runs on. My parallelization is very simple, in that all the

5条回答
  •  野性不改
    2020-11-29 15:27

    In a similar case I opted for separate processes and the little bit of necessary communication trough network socket. It is highly portable and quite simple to do using python, but probably not the simpler (in my case I had also another constraint: communication with other processes written in C++).

    In your case I would probably go for multiprocess, as python threads, at least when using CPython, are not real threads. Well, they are native system threads but C modules called from Python may or may not release the GIL and allow other threads them to run when calling blocking code.

提交回复
热议问题