title: Wait for process to open in python
body: <p>I'm trying make python program which waits to process to open and then it does few things, <br>
  in my case those "few things" will be in function named action(). <br>
  I'm a little complicated with this, here's what I did until now. <br>
  I've found that function which checks if process is running from the tasklist.exe<br></p>
  
  <pre><code>def isWindowsProcessRunning( exeName ) :            
      import subprocess    
      process = subprocess.Popen( 
          'tasklist.exe /FO CSV /FI "IMAGENAME eq %s"' % exeName,
          stdout=subprocess.PIPE, stderr=subprocess.PIPE,
          universal_newlines=True )
      out, err = process.communicate()    
      try : return out.split("\n")[1].startswith('"%s"' % exeName)
      except : return False
  </code></pre>
  
  <p>And I thought to use that in that way: <br></p>
  
  <pre><code>if( isWindowsPrecessRunning("chrome.exe") == False ):
      print "Waiting for chrome to open.."
      while( True ):
          if( isWindowsPrecessRunning("chrome.exe") == True ):
              action()
  else:
      print "Chrome must be closed when the program starts, please close chrome, and re-open the program"
  </code></pre>
  
  <p>The problem is that the program was built with "tkinter" for windows, <br>
  and while I turn it on once, and chrome isn't running - the program gets into endless loop. <br>
  That endless loop, prevent the user of the program to do anything, because it opens a clear cmd, and closes it, opens it, closes it and so over- the user can't even close it. <br>
  Does anyone have an idea about how to do it? <br>
  Thanks in advance :)</p>