私はPythonでマルチスレッドを実行しようとしていますが、まだ酸洗い可能性の要件と、コードのOOPをどれだけ維持できるかについて頭を悩ませています。
モジュール レベルで定義された関数を渡すクラス内から 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 もインポートする必要がありますか?