How do I pass large numpy arrays between python subprocesses without saving to disk?

后端 未结 6 1467
说谎
说谎 2020-11-29 21:21

Is there a good way to pass a large chunk of data between two python subprocesses without using the disk? Here\'s a cartoon example of what I\'m hoping to accomplish:

<
6条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 21:39

    Use threads. You probably won't have problems with the GIL.

    The GIL only affects Python code, not C/Fortran/Cython backed libraries. Most numpy operations and a good chunk of the C-backed Scientific Python stack release the GIL and can operate just fine on multiple cores. This blogpost discusses the GIL and scientific Python in more depth.

    Edit

    Simple ways to use threads include the threading module and multiprocessing.pool.ThreadPool.

提交回复
热议问题