title: Race condition using multiprocessing and threading together
body: <p>I wrote the sample program.
  It creates 8 threads and spawns process in each one</p>
  
  <pre><code>import threading
  from multiprocessing import Process
  
  def fast_function():
      pass
  
  def thread_function():
      process_number = 1
      print 'start %s processes' % process_number
      for i in range(process_number):
          p = Process(target=fast_function, args=())
          p.start()
          p.join()
  
  def main():
      threads_number = 8
      print 'start %s threads' % threads_number
      threads = [threading.Thread(target=thread_function, args=()) 
              for i in range(threads_number)]
  
      for thread in threads:
          thread.start()
  
      for thread in threads:
          thread.join()
  </code></pre>
  
  <p>It crashes with several exceptions like this</p>
  
  <pre><code>Exception in thread Thread-3:
  Traceback (most recent call last):
    File "/usr/lib/python2.6/threading.py", line 532, in __bootstrap_inner
      self.run()
    File "/usr/lib/python2.6/threading.py", line 484, in run
      self.__target(*self.__args, **self.__kwargs)
    File "./repeat_multiprocessing_bug.py", line 15, in thread_function
      p.start()
    File "/usr/lib/python2.6/multiprocessing/process.py", line 99, in start
      _cleanup()
    File "/usr/lib/python2.6/multiprocessing/process.py", line 53, in _cleanup
      if p._popen.poll() is not None:
    File "/usr/lib/python2.6/multiprocessing/forking.py", line 106, in poll
      pid, sts = os.waitpid(self.pid, flag)
  OSError: [Errno 10] No child processes
  </code></pre>
  
  <p>Python version 2.6.5. Can somebody explain what I do wrong?</p>