0

I tried to create 4 processes to run and each process add information to a Queue. when I run code the processes start and but when they are done they do not go seem to execute any code beyond the join() statements.

def delta(section,q,track):
    for i in section:
        ca=find_word_in_card(i)
        q.put([i,ca])
        track.value+=1
   
    print(round((track.value/len(w))*100,4))

if __name__ == '__main__':
    queue=Queue()
    track=Value('i',0)


    p1=Process(target=delta, args=(word_seperation[0],queue,track))
    p2=Process(target=delta, args=(word_seperation[1],queue,track))
    p3=Process(target=delta, args=(word_seperation[2],queue,track))
    p4=Process(target=delta, args=(word_seperation[3],queue,track))



    p1.start()
    p2.start()
    p3.start()
    p4.start()

    p1.join()
    p2.join()
    p3.join()
    p4.join()

    print('ended')

code does not reach the print statement and program does not terminate

TheGarry243
  • 63
  • 1
  • 7
  • 1
    So you've verified that `print(round((track.value/len(w))*100,4))` is actually getting printed 4 times? Have you used a debugger to find out which `join()` is being waited on? – Random Davis Nov 03 '20 at 18:08
  • 1
    The code to start processes and below should be in the `if __name__ == '__main__':` guard. – Michael Butscher Nov 03 '20 at 18:08
  • We don't have enough code to run your example. Can you pull out thnigs like `word_separation` and make an example that we can run that sitll has the error? – tdelaney Nov 03 '20 at 18:16
  • Do you run this in a GUI or IDE where the child process prints wouldn't be seen anyway? No print and no exception suggest that these processes are stuck in an infinite loop. If you are running on Windoes, you'll definately want to add the guard suggested above. – tdelaney Nov 03 '20 at 18:20
  • 1
    I have no actual experience with `multiprocessing`, but my understanding is that processes cannot end (and therefore `.join()` won't return) while there are unprocessed items that they have put in a `Queue`. Your main process needs to drain the `Queue` first. – jasonharper Nov 03 '20 at 18:42
  • You probably filled the pipe-buffer underlying the queue (always include imports so we know what you use), [see](https://stackoverflow.com/questions/59196165/deadlock-with-big-object-in-multiprocessing-queue/59198048#59198048). – Darkonaut Nov 03 '20 at 18:45

0 Answers0