title: Python (multiprocessing): How to pass a dictionary as the argument of a worker process initializer function?
body: <p>I'm using a function to initialize the worker processes of a process pool, and this function has a single argument, which is a dictionary. When the process pool is created and the function is called to initialize each worker process I get an error regarding the wrong number of arguments:</p>
  
  <pre><code>TypeError: _init_worker() takes 1 positional argument but 2 were given
  </code></pre>
  
  <p>The process initializer function being used:</p>
  
  <pre><code>def _init_worker(shared_arrays):
  
      _global_shared_arrays = shared_arrays
  </code></pre>
  
  <p>The initializer is being called in the normal way for each worker process:</p>
  
  <pre><code>with multiprocessing.Pool(processes=_NUMBER_OF_WORKER_PROCESSES,
                            initializer=_init_worker, initargs=(arrays_dict)) as pool:
  </code></pre>
  
  <p>I think this has something to do with how dictionaries are passed as the argument, in that the above error always lists the number of items in the dictionary as the number of positional arguments that were passed, as if what's being passed is the keys of the dictionary rather than the dictionary itself. When I step into the code in the debugger this is exactly what's going on, i.e. if there's a single item in the dictionary argument then only the key is passed through to the initializer function, rather than the dictionary itself.</p>
  
  <p>If there are multiple items in the dictionary used as the argument being passed to the initializer function then the above error message is displayed, reporting the number of items in the dictionary as the number of positional arguments given, so it's somehow passing the keys of the dictionary as arguments rather than the dictionary itself.</p>
  
  <p>What am I doing wrong here?</p>