title: Python time function
body: <p>I have code shown below:</p>
  
  <pre><code>import subprocess
  
  def run_command(command):
          p = subprocess.Popen(command, shell=True,
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.STDOUT)
  
          while p.poll() is None:
                  print "Loading mWorker... please wait"
                  time.sleep(2)
  
          return p.communicate()
  </code></pre>
  
  <p>I originally thought the p.communicate() should be prior to the while statement. However I find that this function call will hang (e.g. I do not see anything past the return prompt) if it is not placed at the end of the method. If I run the method as shown above, I will only get 1 print statement and then</p>
  
  <pre><code>    Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in ?
    File "python.py", line 10, in run_command
      time.sleep(2)
  NameError: global name 'time' is not defined
  </code></pre>
  
  <p>Why am I seeing this? Why doesn't time work more than once? And what changes do I need to make so I will continue to see the print statement?</p>