Why doesn't Python include non-blocking keyboard input function?

Steve D'Aprano steve+python at pearwood.info
Tue Oct 25 12:22:02 EDT 2016


On Wed, 26 Oct 2016 01:36 am, Random832 wrote:

> On Tue, Oct 25, 2016, at 02:39, Steven D'Aprano wrote:
>> Not really. I think that lots of people think they need it, but
>> once they write a little utility, they often realise that it's not
>> that useful. That's just my opinion, and I'm one of those guys who
>> wrote one:
>> 
>>
http://code.activestate.com/recipes/577977-get-single-keypress/?in=user-4172944
> 
> Non-blocking (which your example here doesn't even do) isn't the same
> thing as character-at-a-time. 


Heh, I just realised exactly the same thing. I wondered how many responses
this thread would get before somebody noticed. Thanks Random.

You're right, of course. My code blocks.

So how would you do non-blocking keyboard input? How would it work? What
would be the interface?


> It doesn't even imply it, technically - 
> you could want to do other stuff and occasionally check if the user has
> entered a line, though *that* is even *more* involved on Windows because
> it means you can't do it with msvcrt.kbhit.




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list