-2

Title says it all, is it possible to make python sleep for less than a second? WORKS:

import time
print ("foo")
time.sleep(0.2) #talking about the value of the time
print ("bar")

If not, then is there any other way? Thanks Using python 3.2.2 EDIT: Thanks guys, I'm pretty sure I have tried the above code before and it didn't work. Oh well... sorry for your waste if time. It worked now and I upgraded to 3.3

josh
  • 1,205
  • 4
  • 14
  • 14
  • 1
    Have you tried this? This is very valid code. And for the love of all that is computable, please switch to python3.3, which is the stable 3.x release – inspectorG4dget Jan 21 '14 at 18:41
  • Did you actually try this? Your code already works. – Martijn Pieters Jan 21 '14 at 18:41
  • Answer is: "yes", for example see your own code ;-) – sphere Jan 21 '14 at 18:42
  • 2
    Did you read the [`time.sleep()` documantion](http://docs.python.org/3/library/time.html#time.sleep)? If so, what wasn't clear or match your requirements? – Martijn Pieters Jan 21 '14 at 18:42
  • 4
    this is a little complicated: so what you need to do is select the code you put in your question, copy it, paste it into your interactive session or .py file, and run it. voila! – mhlester Jan 21 '14 at 18:42
  • 3
    @inspectorG4dget: The OP may be on a Ubuntu or Debian release which still provides 3.2. It doesn't really matter here. – Martijn Pieters Jan 21 '14 at 18:43
  • No real question here, at least no such question that cannot be answered by interpreter. Downvote for that. And BTW: see comments above, they're helpful. – Filip Malczak Jan 21 '14 at 18:44
  • possible duplicate of [usleep in Python](http://stackoverflow.com/questions/5568646/usleep-in-python) – tripleee Jan 21 '14 at 18:46

1 Answers1

0

Based on the time.sleep() documentation:

The actual suspension time may be less than that requested because any caught signal will terminate the sleep() following execution of that signal’s catching routine. Also, the suspension time may be longer than requested by an arbitrary amount because of the scheduling of other activity in the system.

So it works but there are no guarantees.

Simeon Visser
  • 118,920
  • 18
  • 185
  • 180