title: Python Thread Scheduling
body: <p>I am trying to implement a ThreadPool + Scheduler in Python 2.7 with the module Threading. My pool contains threads that are allocated up front, and my scheduler handles which thread should perform the task. I have some threads that execute a system process, and wait for the result of it. These system calls can take a very long time, and I was hoping to be able to reuse the thread while the task is executing.</p>
  
  <p>Example:</p>
  
  <ol>
  <li>ThreadPool has 8 threads</li>
  <li>8 tasks come in all together</li>
  <li>9th task comes in after a small delay</li>
  <li>Task 1 takes 1024 years (Maybe it could use some optimization).</li>
  <li>Tasks 2-8 take 1 year.</li>
  <li>Task 9 comes in, and it only takes 1 second.</li>
  <li>Task 9 can't be executed because all threads are being used.</li>
  </ol>
  
  <p>Task 1 has code similar to this</p>
  
  <pre><code>build_process = subprocess.Popen(build_command, shell=False)
  build_process.wait()
  </code></pre>
  
  <p>Is there anyway to grab the Thread from Task1 while it's waiting, and do Task 9? Then when Task 9 finishes go back to Task 1 (waiting for the process to finish?) Does Python already have something like this implemented?</p>