単一の関数の複数のforループに対してマルチスレッドを実装する方法はありますか?私は別の機能を持っていればそれが達成できることを認識していますが、同じ機能の下に置くことは可能です。Pythonの単一の関数で複数のforループを並列に実行する方法
def sqImport():
for i in (0,50):
do something specific to 0-49
for i in (50,100):
do something specific to 50-99
for i in (100,150):
do something specific to 100-149
3つの別々の機能は、ループの異なる3用があるならば、私たちが行うことができます:たとえば
threadA = Thread(target = loopA)
threadB = Thread(target = loopB)
threadC = Thread(target = loopC)
threadA.run()
threadB.run()
threadC.run()
# Do work indepedent of loopA and loopB
threadA.join()
threadB.join()
threadC.join()
しかし、単一の関数の下でこれを達成する方法はありますか?
を可能にする機能を変更していますか? – exilit
多分[multiprocessing.pool.Pool](https://docs.python.org/3.6/library/multiprocessing.html#multiprocessing.pool.Pool)があなたを鼓舞します。 – handle
これを達成するにはnode.jsを試してください –