I was using the 'apply_async' function in Python's 'multiprocessing' library, and using a 'Thread Pool' to run certain functions for my program.
The function sent as argument to 'apply_async' did not even execute. I was looking for an error, and did not get any.
Check this sample program below:
import multiprocessing
def foo(x):
print(x)
if __name__ == '__main__':
multiprocessing.freeze_support()
with multiprocessing.Pool(10) as pool:
res = pool.apply_async(foo, args=("Hello",))
It is not printing the expected output, 'Hello', as 'apply_async' is not running the function 'foo' in it.
Use 'res.get()' like below, to get the function to run:
The output:
Check the official Python Documentation: https://docs.python.org/3/library/multiprocessing.html