I am running into some deadlock with the following code.
import time
from multiprocessing import Process, Queue
import numpy as np
def f(q):
q.put([(np.random.rand(50000), 0.993) for _ in range(10000)])
def g(q):
time.sleep(3) # to make both functions take approximately the same amount of time
q.put('X' * 100000)
if __name__ == '__main__':
print([(np.random.rand(50000), 0.993) for _ in range(10000)])
queue = Queue()
p = Process(target=g, args=(queue,))
p.start()
obj = queue.get()
p.join() # after get() as suggested in the docs
print("Done g")
print(obj)
queue = Queue()
p = Process(target=f, args=(queue,))
p.start()
obj = queue.get()
p.join() # after get() as suggested in the docs
print("Done f")
print(obj)
The function g seems to be computed easily in the subprocess whereas running the process computing f results in a deadlock (it seems).
I am aware that this is similar to enter link description here. However, the accepted answer suggests either switching q.get() and p.join() or removing p.join() entirely. Doing either does not solve my problem.
Furthermore, the print statement in the beginning shows that doing whatever f
is doing should not take a long time.
UPDATE: I realise that the reason for this might be that the result of f is too big in size. If that is the case I am wondering what the standard way of exchanging large data between processes is.