Was ich versuche zu tun ist zu überprüfen, welche Multiprozessing für meine Daten am besten ist. Ich habe versucht, diese Schleife zu Multi-Prozess-:Python Multiprozess/Threading Schleife.
def __pure_calc(args):
j = args[0]
point_array = args[1]
empty = args[2]
tree = args[3]
for i in j:
p = tree.query(i)
euc_dist = math.sqrt(np.sum((point_array[p[1]]-i)**2))
##add one row at a time to empty list
empty.append([i[0], i[1], i[2], euc_dist, point_array[p[1]][0], point_array[p[1]][1], point_array[p[1]][2]])
return empty
Nur reine Funktion nimmt 6,52 sec.
Mein erster Ansatz war multiprocessing.map:
from multiprocessing import Pool
def __multiprocess(las_point_array, point_array, empty, tree):
pool = Pool(os.cpu_count())
for j in las_point_array:
args=[j, point_array, empty, tree]
results = pool.map(__pure_calc, args)
#close the pool and wait for the work to finish
pool.close()
pool.join()
return results
Wenn ich andere Antworten überprüft, wie funktionieren Multi-Prozess-es sollte so einfach sein: Karte (Anruffunktion, Eingänge) - fertig. Aber aus irgendeinem Grund schließt mein multiprocess meine Eingaben nicht aus, steigender Fehler, dass das scipy.spatial.ckdtree.cKDTree-Objekt nicht einklagbar ist. So
Ich habe versucht, mit apply_async:
from multiprocessing.pool import ThreadPool
def __multiprocess(arSegment, wires_point_array, ptList, tree):
pool = ThreadPool(os.cpu_count())
args=[arSegment, point_array, empty, tree]
result = pool.apply_async(__pure_calc, [args])
results = result.get()
Es mit heraus Probleme laufen. Für meine Testdaten beziehe ich es in 6,42 sek.
Warum apply_async akzeptiert ckdtree mit keinem Problem und pool.map nicht? Was muss ich ändern, damit es läuft?