i have now managed to start a function in parallel using multithreading. So far it works quite well.
thread_list = []
for thr in range(threads):
thread = threading.Thread(target=Extract_high_vegetation, args=(kachelnummer, thr, os.path.join(output_dir, kachelnummer, kachelnummer + '_input.txt'), os.path.join(output_dir, kachelnummer, 'Output'))
thread_list.append(thread)
thread_list[thr].start()
for thread in thread_list:
thread.join()
Now I would like to process the command in a separate function, so that I can only pass the target function and the argument of the target function in each case.
def multithreading(target_function, argument):
thread_list = []
for thr in range(threads):
thread = threading.Thread(target = target_function, args = argument)
thread_list.append(thread)
thread_list[thr].start()
for thread in thread_list:
thread.join()
def Extract_high_vegetation(kachelnummer, i, input_LAZ_file, output_folder):
if not os.path.isdir(output_folder):
os.makedirs(output_folder)
kachelnummer = kachelnummer.replace('_', '-')
def Extract_low_vegetation(kachelnummer, i, input_LAZ_file, output_folder):
if not os.path.isdir(output_folder):
os.makedirs(output_folder)
kachelnummer = kachelnummer.replace('_', '-')
multithreading(Extract_high_vegetation, kachelnummer, thr, os.path.join(output_dir, kachelnummer, kachelnummer + '_input.txt'), os.path.join(output_dir, kachelnummer, 'High'))
multithreading(Extract_low_vegetation, kachelnummer, thr, os.path.join(output_dir, kachelnummer, kachelnummer + '_input.txt'), os.path.join(output_dir, kachelnummer, 'Low'))
The two "vegetation" functions are not exhaustive, but are only intended to clarify the arguments. Unfortunately I can't manage to pass the argument, which consists of different variables for the target function. Can someone please tell me how to pass the arguments to the target function? As I understand it, I would have to pack the second part (starting with "tile number") into a single string. Currently there are a lot more of them.
Thanks a lot