0
我想在python中执行多线程,我仍然试图让我的头围绕picklability要求和多少我可以保持我的代码OOP。Python中,你可以传递一个模块级功能ThreadPoolExecutor从一个类内
你可以在类中传递ThreadPoolExecutor来传递一个在模块级定义的函数吗?我的设置如下:
moduleA.py:
def foo():
run some stuff
class bar(object):
def runThreads(self):
executor = futures.ThreadPoolExecutor(5)
executor.submit(foo) # do this 5 times in some sort of loop
我希望能够从一个单独的模块
moduleB.py
from moduleA import bar
A = bar()
A.runThreads()
将调用此这项工作?我是否也需要导入foo?
提示:试试吧!然后问一个问题,如果你不明白发生了什么。 –