我需要在32位系统范围内运行Python脚本,以便通过第三方应用程序生成/收集数据。但是我想通过numba
使用GPU处理数据,所以它必须在64位Python环境中运行。在
我已经设置了一个64位Pythonvirtualenv
,并测试了一些简单的numba
代码,这些代码在其中运行良好。那么我该如何在父进程中编写代码来调用子进程(multiprocessing
或{virtualenv
并使用numba进行计算?更具体地说:
multiprocessing
或{可能的代码示例:
def func_32():
# data collection
# using 3rd party API
return data
def func_64(data, output):
# switch to 64 bit virtual env
# using virtualenvwrapper-win
os.system('workon env64bit')
# numba data process
# results stored in output
return None
def main():
data = func_32()
# I think I only need one process since it will be in GPU not CPU
p = multiprocessing.Process(target=func_64, args=(data, output))
p.start()
return output
我在示例代码中遗漏了什么?在
我看到了这个问题Spawn multiprocessing.Process under different python executable with own path,并在给出Python版本(2.7.5 32位,2.7.15 64位)时发现了我的答案。在
但是为了在虚拟环境中使用64位Python包,我最终主要从
activate_this.py
(位于virtualenv文件夹中)复制代码,以更改Python搜索路径等。在我认为使用
multiprocessing
可以更方便地在父进程和子进程之间传递数据,尤其是大量数据。在相关问题 更多 >
编程相关推荐