title: Python: Process in one Thread stopping a Process in another Thread from finishing
body: <p>I'd appreciate some help with threading, which I pretty new to. </p>
  
  <p>The example code is not exactly what I’m doing (‘notepad’ and ‘calc’ are just example commands), but a simplified version that shows my problem.</p>
  
  <p>I want to run two seperate threads that each run a different command a number of times. I would like the code to do this:</p>
  
  <ol>
  <li>Start the first instance of ‘notepad’ and ‘calc’ simultaneously
  (which it does) </li>
  <li>When I close an instance of ‘notepad’, to open the
  next instance of ‘notepad’. </li>
  <li>When I close an instance of ‘calc’, to
  open the next instance of ‘calc’.</li>
  <li>[edit] I want the script to wait until both threads have finished, as it needs to do some processing of the output from these.</li>
  </ol>
  
  <p><strong>However, when I close an instance of ‘notepad’, the next instance of ‘notepad’ does not start until I’ve closed the current instance of ‘calc’ and vice versa.</strong> With a bit of de-bugging, it looks like the process (from Popen) for the closed instance of 'notepad' doesn't finish until the current 'calc' is closed.</p>
  
  <p>Running Python 2.7 on Windows 7</p>
  
  <p>Example Code:</p>
  
  <pre><code>from subprocess import Popen, PIPE, STDOUT
  from threading import Thread
  
  def do_commands(command_list):
  
      for command in command_list:
          proc = Popen("cmd.exe", stdin=PIPE, stdout=PIPE, stderr=STDOUT)
          stdout_value, stderr_value = proc.communicate(input=command)
  
  # MAIN CODE
  A_command_list = ["notepad\n", "notepad\n", "notepad\n" ]
  B_command_list = ["calc\n", "calc\n", "calc\n" ]
  
  A_args = [A_command_list]
  B_args = [B_command_list]
  
  A_thread = Thread(target=do_commands, args=(A_args))
  B_thread = Thread(target=do_commands, args=(B_args))
  
  A_thread.start()
  B_thread.start()
  
  A_thread.join()
  B_thread.join()
  </code></pre>
  
  <p>Thanks in advance :-)</p>
  
  <p>Nick</p>