title: python parallel processes return exit code
body: <p>lets see if I can make this clear... I'm a total Python beginner so bear with me, this is my first python program (though I'm familiar with basic scripting in a few other languages). I've been searching around for hours and I'm sure the answer to this is fairly simple but I have yet to get it to work properly.</p>
  
  <p>I'm writing a code that should launch multiple commandline processes, and when each one finishes I want to update a cell in a QTableWidget. The table has a row for each process to run, and each row has a cell for the "status" of the process.</p>
  
  <p>I can run this no problem if I just do a for loop, spawning one process per row using <code>subprocess.call()</code> however this is too linear and I would like to fire them all off at the same time and not hang the program for each loop cycle. I've been digging through the subprocess documentation and am having a really hard time with it. I understand that I need to use <code>subprocess.Popen</code> (which will prevent my program from hanging while the process runs, and thus I can spawn multiple instances). Where I run into trouble is getting the exit code back so that I can update my table, without hanging the program - for instance using <code>subprocess.wait()</code> followed by a <code>subprocess.returncode</code> still just sticks until the process completes. I need a sort of "when process completes, check the exit code and run a function that updates the QTableWidget."</p>
  
  <p>I did find these two posts that seemed to get me going in the right direction, but didn't quite get me there:</p>
  
  <p><a href="https://stackoverflow.com/questions/16768290/understanding-popen-communicate">Understanding Popen.communicate</a></p>
  
  <p><a href="https://stackoverflow.com/questions/5631624/how-to-get-exit-code-when-using-python-subprocess-communicate-method">How to get exit code when using Python subprocess communicate method?</a></p>
  
  <p>Hopefully that made sense. Here's a simplified version of my code, I realize it is half-baked and half-broken but I've been screwing around with it for over an hour and I've lost track of a few things...</p>
  
  <pre><code>import os, subprocess
  
  ae_app = 'afterfx'
  ae_path = os.path.join('C:/Program Files/Adobe/Adobe After Effects CC 2015/Support Files', ae_app + ".exe")
  filename = "E:/Programming/Python/Archive tool/talk.jsx"
  commandLine = 'afterfx -noui -r ' + filename
  
  processList = [commandLine]
  processes = []
  
  for process in processList:
      f = os.tmpfile()
      aeProcess = subprocess.Popen(process, executable=ae_path, stdout=f)
      processes.append((aeProcess, f))
  
  for aeProcess, f in processes:
      # this is where I need serious help...
      aeProcess.wait()
      print "the line is:"
      print aeProcess.returncode
  </code></pre>
  
  <ul>
  <li>Spencer</li>
  </ul>