Note that there are some explanatory texts on larger screens.

plurals
  1. POPython multiprocessing.Queue deadlocks on put and get
    primarykey
    data
    text
    <p>I'm having deadlock problems with this piece of code:</p> <pre><code> def _entropy_split_parallel(data_train, answers_train, weights): CPUS = 1 #multiprocessing.cpu_count() NUMBER_TASKS = len(data_train[0]) processes = [] multi_list = zip(data_train, answers_train, weights) task_queue = multiprocessing.Queue() done_queue = multiprocessing.Queue() for feature_index in xrange(NUMBER_TASKS): task_queue.put(feature_index) for i in xrange(CPUS): process = multiprocessing.Process(target=_worker, args=(multi_list, task_queue, done_queue)) processes.append(process) process.start() min_entropy = None best_feature = None best_split = None for i in xrange(NUMBER_TASKS): entropy, feature, split = done_queue.get() if (entropy &lt; min_entropy or min_entropy == None) and entropy != None: best_feature = feature best_split = split for i in xrange(CPUS): task_queue.put('STOP') for process in processes: process.join() return best_feature, best_split def _worker(multi_list, task_queue, done_queue): feature_index = task_queue.get() while feature_index != 'STOP': result = _entropy_split3(multi_list, feature_index) done_queue.put(result) feature_index = task_queue.get() </code></pre> <p>When I run my program, it works fine for several runs through <code>_entropy_split_parallel</code>, but eventually deadlocks. The parent process is blocking on <code>done_queue.get()</code>, and the worker process is blocking on <code>done_queue.put()</code>. Since the queue is always empty when this happens, blocking on <code>get</code> is expected. What I don't understand is why the worker is blocking on <code>put</code>, since the queue is obviously not full (it's empty!). I've tried the <code>block</code> and <code>timeout</code> keyword arguments, but get the same result.</p> <p>I'm using the multiprocessing backport, since I'm stuck with Python 2.5.</p> <hr> <p>EDIT: It looks like I'm also getting deadlock issues with one of the examples provided with the multiprocessing module. It's the third example from the bottom <a href="http://docs.python.org/library/multiprocessing.html" rel="noreferrer">here.</a> The deadlocking only seems to occur if I call the test method many times. For example, changing the bottom of the script to this:</p> <pre><code> if __name__ == '__main__': freeze_support() for x in xrange(1000): test() </code></pre> <hr> <p>EDIT: I know this is an old question, but testing shows that this is no longer a problem on windows with Python 2.7. I will try Linux and report back.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload