Title: Hot python input loop
Tags: python;input;loops;timer
Question: I'd like to have something similar to the following pseudo code:
while input is not None and timer < 5:
input = getChar()
timer = time.time() - start
if timer &gt;= 5:
print "took too long"
print input
Anyway to do this without threading? I would like an input method that returns whatever has been entered since the last time it was called, or None (null) if nothing was entered.
Comment: I *want* the hot loop. That's the question. I can slow it down with the `time.sleep` or whatever.

Comment: You could `time.sleep` for small periods of time (0.1 seconds or so, maybe less if you need low latency) to avoid a hot loop, or at least cool it down.

Comment: related "How to set time limit on input" http://stackoverflow.com/questions/2933399/how-to-set-time-limit-on-input

Comment: If you use a non-blocking IO message, you'll end up in a hot loop—one that uses all available processing power to take input. You're much better off using `threading.Timer` to trigger the fail condition if it takes too long.

Comment: Please edit your question title to reflect the actual content of your question. "Easy Python input question" tells almost nothing about what the question is. The headline should be more descriptive. It will help people to find and answer your question.


Here is another answer: On *nix you want select with sys.stdin. On Windows you want msvcrt.kbhit() and msvcrt.getch().

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 5, 'ContentLicense': 'CC BY-SA 2.5', 'CreationDate': '2010:00:06/16/10', 'FavoriteCount': 0.0, 'PostTypeId': 1, 'Tags': '<python><input><loops><timer>', 'Title': 'Hot python input loop', 'ViewCount': 754, 'id': 3050133, 'user_AboutMe': '<h3>Me</h3>\n\n<p>I\'m a software engineer living in New York City. Currently I\'m available for consulting work, previously I founded <a href="http://byjakt.com" rel="nofollow">JAKT</a> a leading design and development consultancy that uses technology to solve problems for entrepreneurs and cor\xadpo\xadra\xadtions.</p>\n\n<p>You can read more about me at <a href="http://www.joshuakehn.com" rel="nofollow">joshuakehn.com</a> or <a href="http://twitter.com/joshkehn" rel="nofollow">@joshkehn</a>.</p>\n\n<h3>Common Links:</h3>\n\n<p><a href="http://blog.stackoverflow.com/2010/09/good-subjective-bad-subjective/">Guidelines for Constructive Questions</a><br>\n<a href="http://programmers.stackexchange.com/faq">FAQ</a></p>\n', 'user_AccountId': 62488.0, 'user_DisplayName': 'Josh K', 'user_Reputation': 27680.0, 'user_Views': 1624.0, 'user_id': 185657.0}}