I have 2 different methods. Each of the 2 methods return a list. One of the methods also takes in a parameter.
I am executing the two methods in parallel.
However I do not understand how to get the return values of the two functions from my function call ?
Also I got those code from elsewhere, and I do not understand what exactly is the significance of "is_something1" and "is_something2" and what is its role here?
from concurrent.futures import ThreadPoolExecutor
import datetime
import time
def func1():
print("function1 called "+ str(datetime.datetime.now())+"\n")
time.sleep(5)
print("function1 ended "+ str(datetime.datetime.now())+"\n")
list1 = [4,5,6]
return list1
def func2(str_sample):
print("function2 called "+ str(datetime.datetime.now())+"\n")
time.sleep(5)
print("function2 ended "+ str(datetime.datetime.now())+"\n")
list2 = [1,2,3]
return list2
def run_io_tasks_in_parallel(tasks):
with ThreadPoolExecutor() as executor:
running_tasks = [executor.submit(task) for task in tasks]
for running_task in running_tasks:
running_task.result()
results = run_io_tasks_in_parallel([
lambda: {'is_something1': func1()},
lambda: {'is_something2': func2()},
])