I am trying to update two values of a queue at the same time, but my code ends up in an infinite loop. I'm running it on Django View, the code below runs well but when I try it on Django it just keeps waiting. What could be happening?
import multiprocessing
from multiprocessing import Process
ret = {'algo' : 'hola', 'beto' : 'oka'}
def algo(queue):
ret = queue.get()
ret['algo'] = False #This is actually an API call value
queue.put(ret)
def beta(queue):
ret = queue.get()
ret['beto'] = True #This is actually an API call value
queue.put(ret)
queue = multiprocessing.Queue()
queue.put(ret)
p1 = Process(target=algo, args=(queue,))
p2 = Process(target=beta, args=(queue,))
p1.start()
p2.start()
p1.join()
p2.join()
q = queue.get()
Code in Django Views.py
ret = {'algo' : 'hola', 'beto' : 'oka'}
def algo(queue):
ret = queue.get()
ret['algo'] = False #This is actually an API call value
queue.put(ret)
def beta(queue):
ret = queue.get()
ret['beto'] = True #This is actually an API call value
queue.put(ret)
def audio(request):
if request.method == 'POST':
AUDIO_FILE = path.join(os.getcwd(), "audio.wav")
# use the audio file as the audio source
r = sr.Recognizer()
with sr.AudioFile(AUDIO_FILE) as source:
audio = r.record(source)
queue = multiprocessing.Queue()
queue.put(ret)
p1 = Process(target=algo, args=(queue,))
p2 = Process(target=beta, args=(queue,))
p1.start()
p2.start()
p1.join()
p2.join()
q = queue.get()
print(q)