我有两个函数func1(),func2()它们相互独立,可以在两个线程中运行。我正在使用threading库python3来运行这两个线程。不过里面func1(),我也运行for使用并行循环joblib。因此,使用线程以及 joblib 会给出以下警告 -
/usr/local/lib/python3.6/dist-packages/joblib/parallel.py:547: UserWarning: Multiprocessing-backed parallel loops cannot be nested below threads, setting n_jobs=1,
然后里面的 for 循环func1()只是按顺序运行。
以下是代码片段的示例:
from joblib import Parallel, delayed
import threading
from math import sqrt
class MyThread(threading.Thread):
def __init__(self, sample, type):
threading.Thread.__init__(self)
self.type = type
self.sample = sample
def run(self):
if self.type=='func1':
self.sample.func1()
else:
self.sample.func2()
class Sample:
def func1(self):
print('this function runs for …Run Code Online (Sandbox Code Playgroud)