queue.get returns NoneType object?
<p>I modified the example on Joinable queues on this link <a href="https://pymotw.com/2/multiprocessing/communication.html" rel="nofollow">https://pymotw.com/2/multiprocessing/communication.html</a> to run a function I wrote instead of a Task object. The modified code is listed below. The problem I am getting is that the consumers get poisoned without putting None in the tasks queue. They exit before completing the tasks. So I removed the check on None (as shown below) from the run function and I caught this exception:</p>

<p>'NoneType' object is not callable</p>

<p>I am sure that the None is not passed yet since the message "Poisoning Consumers" is not yet printed</p>

<pre><code>import multiprocessing as mp
import MyLib

# Subclass of Process
class Consumer(mp.Process):

    def __init__(self, task_queue, result_queue):
        mp.Process.__init__(self)
        self.task_queue = task_queue
        self.result_queue = result_queue
        self.daemon = True

    # A method that defines the behavior of the process
    def run(self):
        proc_name = self.name
        while True:
            try:
                next_task = self.task_queue.get()
                # if next_task is None:
                #     # Poison pill means shutdown
                #     print('%s: Exiting' % proc_name)
                #     self.task_queue.task_done()
                #     break

                mxR, disC = next_task()
                self.task_queue.task_done()
                self.result_queue.put((mxR, disC))
            except Exception as e:
                print(e)

        return


if __name__ == '__main__':
    # Establish communication queues
    tasks = mp.JoinableQueue()
    results = mp.Queue()

    # Start consumers
    num_consumers = mp.cpu_count() * 2
    print('Creating %d consumers' % num_consumers)
    consumers = [ Consumer(tasks, results)
                  for i in range(num_consumers) ]
    for w in consumers:
        w.start()

    # Enqueue jobs

    trials = 10
    Tx_Range = 50
    prnts = 4
    for tx in list(range(30, 200, 20)):
        file_name = 'output_{}_{}.txt'.format(tx,prnts)
        output_file = open(file_name,'a')
        output_file.write('Nodes\tTx_Range\tAvg_Rings\tAvg_Disc\n')
        for n in list(range(50, 101, 50)):
            ring_sum, disc_sum = 0, 0
            for i in range (0, trials):
                tasks.put(MyLib.GBMR_mp(1000, 1000, n, prnts, tx, False, results))

            print('Done putting jobs')
            for i in range (0, trials):
                mxR, discN = results.get()
                ring_sum += mxR
                disc_sum += discN
            avg_ring = ring_sum/trials
            avg_disc = disc_sum/trials
            print('Done Collecting Results, avg_disc = ', avg_disc,' and avg_rings = ', avg_ring)
            s = '{}\t\t{}\t\t{}\t\t{}\n'.format(n,tx,avg_ring,avg_disc)
            print('Nodes', n, 'is Done for Tx_range', tx)
            output_file.write(s)
        output_file.close()



    # Add a poison pill for each consumer
    print('Poisoning Consumers')
    for i in range(num_consumers):
        tasks.put(None)

    # Wait for all of the tasks to finish
    tasks.join()
</code></pre>

<p>What could be the cause of this problem? Could it be the queue.get() is returning None?</p>

<p>Thanks in advance</p>