title: Postponing functions in python
body: <p>In JavaScript I am used to being able to call functions to be executed at a later time, like this</p>
  
  <pre><code>function foo() {
      alert('bar');
  }
  
  setTimeout(foo, 1000);
  </code></pre>
  
  <p>This does not block the execution of other code.</p>
  
  <p>I do not know how to achieve something similar in Python. I can use sleep</p>
  
  <pre><code>import time
  def foo():
      print('bar')
  
  time.sleep(1)
  foo()
  </code></pre>
  
  <p>but this will block the execution of other code. (Actually in my case blocking Python would not be a problem in itself, but I would not be able to unit test the method.)</p>
  
  <p>I know threads are designed for out-of-sync execution, but I was wondering whether something easier, similar to <code>setTimeout</code> or <code>setInterval</code> exists.</p>