title: Python - "can't pickle thread.lock" error when creating a thread under a multiprocess in Windows
body: <p>I'm getting stuck on what I think is a basic multiprocess and threading issue. I've got a multiprocess set up, and within this a thread. However, when I set up the thread class within the <strong>init</strong> function, I get the following error: </p>
  
  <p>"TypeError: can't pickle thread.lock objects".</p>
  
  <p>However, this does not happen if the thread is set up outside of the <strong>init</strong> function. Does anyone know why this is happening? Note I'm using Windows.</p>
  
  <p>Some code is below to illustrate the issue. As typed below, it runs fine. However if print_hello() is called from within the DoStuff <strong>init</strong> def, then the error occurs, if it's called within the multi-process run() def then it's fine.</p>
  
  <p>Can anyone point me in the right direction so it runs fine when called from <strong>init</strong>? thanks!</p>
  
  <pre><code>import multiprocessing
  import threading
  import time
  
  class MyProcess(multiprocessing.Process):
  
      def __init__(self, **kwargs):
          super(MyProcess, self).__init__(**kwargs)
          self.dostuff = DoStuff()
  
      def run(self):
          print("starting DoStuff")
          # This works fine if the line below is uncommented and __init__ self.print_hello() is commented...
          self.dostuff.print_hello()
  
  
  class DoStuff(object):
      def __init__(self, **kwargs):
          super(DoStuff, self).__init__(**kwargs)
  
          # If the following is uncommented, the error occurs...
          #   Note it also occurs if the lines in start_thead are pasted here...
          # self.print_hello()
  
      def print_hello(self):
          print "hello"
          self.start_thread()
  
      def start_thread(self):
          self.my_thread_instance = MyThread()
          self.my_thread_instance.start()
          time.sleep(0.1)
  
  
  class MyThread(threading.Thread):
      def __init__(self):
          super(MyThread, self).__init__()
  
      def run(self):
          print("Starting MyThread")
  
  
  if __name__ == '__main__':
      mp_target = MyProcess()       # Also pass the pipe to transfer data
      # mp_target.daemon = True
      mp_target.start()
      time.sleep(0.1)
  </code></pre>