I am executing a function using concurrent.futures.ThreadPoolExecutor() where each thread loads a module from site-packages. Here is how the code goes,
def execFn(r):
try:
module = sys.modules['xxx.abc']
except KeyError:
module = import_module('xxx.abc') #this will find and load values in sys.modules
....
result = []
rlist = [1,2,3,4,5]
with concurrent.futures.ThreadPoolExecutor(10) as executor:
futureList = {executor.submit(execFn, r):r for r in rlist}
for future in concurrent.futures.as_completed(futureList):
result.append(future.result())
While one of the two thread is able to load the module named xxx.abc present in site-packages, the other is not able to. Is it because one thread locks the module? How can I resolve this issue?