473,471 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Non-blocking raw_input

Hi,

Could anyone tell me whether I can find a non blocking alternative to
raw_input that works on windows? Is there not a python way of achieving
this? Can I find it somewhere in the documentation?
Any help will be highly appreciated

Cheers
j.
Jul 19 '05 #1
3 6390
Jorge Louis de Castro wrote:
Could anyone tell me whether I can find a non blocking alternative to
raw_input that works on windows? Is there not a python way of achieving
this? Can I find it somewhere in the documentation?
Any help will be highly appreciated


Depending on what your requirements are (since you don't really say),
the functionality in the standard msvcrt module might help.
Jul 19 '05 #2
Jorge Louis de Castro wrote:
I have indeed tried the msvcrt module but none of the examples given works
as described on a XP+SP2 box.


what examples? how did you run the examples?

(the keyboard interface functions in msvcrt only work if the program's attached to
a Windows console. if you run the program under an IDE, that may not be true).

</F>

Jul 19 '05 #3
On Tue, 28 Jun 2005 10:29:35 +0000, "Jorge Louis de Castro"
<jo****@hotmail.com> declaimed the following in comp.lang.python:
Basically, I just want to wait for user input and echo it, though while the
user is not typing anything I'd like to have a background thread printing
"Come on, you're taking too long" or similar stuff.
The problem is that I can only read (and in batch) the background thread
printout messages on the console after feeding the raw_input function.
That's probably a fault of the Window's console handler, which
is blocking output while a read is active; the thread is likely trying
to do the output but the OS blocks.

On Windows, the msvcrt module is probably it. The documentation
does state that msvcrt.getch() /blocks/ if no key has been pressed, but
does not require an <enter> to complete. Since you don't want blocking
behavior, you will likely need to use msvcrt.kbhit()

A quick&dirty example, some parts could be cleaner, but it does
run...

-=-=-=-=-=-=-=-=-
E:\UserData\Dennis Lee Bieber\My Documents>script1.py
Type Q to quit
Well?... Type something
You entered the character 'a'
Well?... Type something
You entered the character 'D'
You entered the character 'F'
You entered the character 'D'
You entered the character 'E'
Well?... Type something
You entered the character 'd'
You entered the character 'e'
You entered the character 'n'
You entered the character 'n'
You entered the character 'i'
You entered the character 's'
You entered the character ' '
You entered the character 'l'
You entered the character 'e'
You entered the character 'e'
You entered the character ' '
You entered the character 'b'
You entered the character 'i'
You entered the character 'e'
You entered the character 'b'
You entered the character 'e'
You entered the character 'r'
Well?... Type something
Well?... Type something
You entered the character 'q'

E:\UserData\Dennis Lee Bieber\My Documents>
-=-=-=-=-=-=-=-=-
import msvcrt
import time

print "Type Q to quit"

i = 0
while True:
time.sleep(0.05)
if msvcrt.kbhit():
ch = msvcrt.getch()
else:
ch = None

if ch:
print "You entered the character '%s'" % ch
i = 0
else:
i += 1
if i == 40:
print "Well?... Type something"
i = 0

if ch == "q" or ch == "Q":
break

-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: lothar | last post by:
re: 4.2.1 Regular Expression Syntax http://docs.python.org/lib/re-syntax.html *?, +?, ?? Adding "?" after the qualifier makes it perform the match in non-greedy or minimal fashion; as few...
5
by: klaus triendl | last post by:
hi, recently i discovered a memory leak in our code; after some investigation i could reduce it to the following problem: return objects of functions are handled as temporary objects, hence...
25
by: Yves Glodt | last post by:
Hello, if I do this: for row in sqlsth: ________pkcolumns.append(row.strip()) ________etc without a prior:
32
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
8
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this? Mixed-mode is incredibly convenient, but if I...
14
by: Patrick Kowalzick | last post by:
Dear all, I have an existing piece of code with a struct with some PODs. struct A { int x; int y; };
11
by: ypjofficial | last post by:
Hello All, So far I have been reading that in case of a polymorphic class ( having at least one virtual function in it), the virtual function call get resolved at run time and during that the...
2
by: Ian825 | last post by:
I need help writing a function for a program that is based upon the various operations of a matrix and I keep getting a "non-aggregate type" error. My guess is that I need to dereference my...
0
by: amitvps | last post by:
Secure Socket Layer is very important and useful for any web application but it brings some problems too with itself. Handling navigation between secure and non-secure pages is one of the cumbersome...
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.