While using keras I found that I couldn't use multiprocessing.Pool. After some troubleshooting I think importing keras is the source of the problem and have created a simple example of this.
import keras
from multiprocessing import Pool
def foo(q,y):
print("In foo")
return q,y
def test(a, b):
x = []
if __name__ == '__main__':
p = Pool(5)
print("Starting")
x = p.starmap(foo, [[a,2],[b,4]])
print("Finished")
p.close()
p.join()
print(x)
if __name__ == '__main__':
test(1,3)
Output
> Starting
When run it outputs "Starting" then hangs. If I remove the keras import it runs fine and outputs [(1, 2), (3, 4)] as expected. Any idea how I can resolve this issue or what might be causing it? I don't fully understand how multiprocessing works with python yet. Thanks!
I am using anaconda and spyder for my code.