在Python并行作业中导入特定的类或函数
如果在传递给服务器.submit的函数中使用某些模块,则需要在modules参数中指定这些模块。见下文:在Python并行作业中导入特定的类或函数,python,pp-python-parallel,Python,Pp Python Parallel,如果在传递给服务器.submit的函数中使用某些模块,则需要在modules参数中指定这些模块。见下文: import os def get_os_name(): return os.name jobserver.submit(get_os_name,modules=('os',)) 但是,我想这样做: from os import name def get_os_name(): return name # Obviously won't work jobserver.subm
import os
def get_os_name():
return os.name
jobserver.submit(get_os_name,modules=('os',))
但是,我想这样做:
from os import name
def get_os_name():
return name
# Obviously won't work
jobserver.submit(get_os_name,modules=('os',))
如何让第二个代码块工作?我尝试用“os.name”之类的东西替换“os”,但没有成功。试试这个:
exec("jobserver.submit(get_os_name,modules=('os',))")