title: How to make a function run for specific seconds without sleep
body: <p>Consider the below code:</p>
  
  <pre><code>def boil():
      print("Boiling")
  
  def cool():
      print("Cooling")
      sleep(2)
  
  start = time.time()   
  boil()
  cool()
  boil()
  cool()
  print(round(time.time()-start)," secs")
  </code></pre>
  
  <p>I want the boil() function to run for 3 seconds without using sleep() so that the final output is 10 secs. How can I do this?</p>
  
  <p>Note: I am creating two set of codes for illustrating sequential and concurrent. Hence I dont want to have sleep() in the boil() as it would make it concurrent when I use threads as below so that the code can execute 2 secs faster:</p>
  
  <pre><code>def boil():
      print("Boiling")
  
  def cool():
      print("Cooling")
      sleep(2)
  
  start = time.time()   
  boil()
  #Here I am cooling and cooking concurrently
  Thread(target=cool).start()
  boil()
  cool()
  print(round(time.time()-start)," secs")
  </code></pre>