title: pickle.PicklingError: Can't pickle <function func at 0x02B3C1B0>: it's not found as __main__.func
body: <p>test.py and main.py is in the same folder, and I execute the main.py, the Interpreter report the following error.</p>
  
  <p>Python environment:python2.7.15</p>
  
  <p>how to fix this issue?</p>
  
  <p>Google told me that this issue is fixed in python3.4, but I want to use this style in python 2.7, how to do it
  test.py</p>
  
  <pre><code>from multiprocessing import Process, Queue
  def interaction(q):
      print '*'*50
      q.put('-'*50)
  q = Queue()
  
  p = Process(target=interaction, args=(q,))
  p.start()
  p.join()
  print q.get()
  </code></pre>
  
  <p>main.py</p>
  
  <pre><code>if __name__ == '__main__':
  
      execfile('test.py')
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\sync360\code\python\oobe_test\multiprocessing_test\demorund\main.py", line 3, in &lt;module&gt;
      execfile('test.py')
    File "test.py", line 13, in &lt;module&gt;
      main()
    File "test.py", line 10, in main
      p.start()
    File "C:\Python27\lib\multiprocessing\process.py", line 130, in start
      self._popen = Popen(self)
    File "C:\Python27\lib\multiprocessing\forking.py", line 277, in __init__
      dump(process_obj, to_child, HIGHEST_PROTOCOL)
    File "C:\Python27\lib\multiprocessing\forking.py", line 199, in dump
      ForkingPickler(file, protocol).dump(obj)
    File "C:\Python27\lib\pickle.py", line 224, in dump
      self.save(obj)
    File "C:\Python27\lib\pickle.py", line 331, in save
      self.save_reduce(obj=obj, *rv)
    File "C:\Python27\lib\pickle.py", line 425, in save_reduce
      save(state)
    File "C:\Python27\lib\pickle.py", line 286, in save
      f(self, obj) # Call unbound method with explicit self
    File "C:\Python27\lib\pickle.py", line 655, in save_dict
      self._batch_setitems(obj.iteritems())
    File "C:\Python27\lib\pickle.py", line 687, in _batch_setitems
      save(v)
    File "C:\Python27\lib\pickle.py", line 286, in save
      f(self, obj) # Call unbound method with explicit self
    File "C:\Python27\lib\pickle.py", line 754, in save_global
      (obj, module, name))
  pickle.PicklingError: Can't pickle &lt;function func at 0x02B3C1B0&gt;: it's not found as __main__.func
  Traceback (most recent call last):
    File "&lt;string&gt;", line 1, in &lt;module&gt;
    File "C:\Python27\lib\multiprocessing\forking.py", line 381, in main
      self = load(from_parent)
    File "C:\Python27\lib\pickle.py", line 1384, in load
      return Unpickler(file).load()
    File "C:\Python27\lib\pickle.py", line 864, in load
      dispatch[key](self)
    File "C:\Python27\lib\pickle.py", line 886, in load_eof
      raise EOFError
  EOFError
  [Finished in 0.3s with exit code 1]
  </code></pre>