473,943 Members | 15,992 Online
Bytes | Software Development & Data Engineering Community
+ 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 6433
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.pytho n:
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\Den nis Lee Bieber\My Documents>scrip t1.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\Den nis 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.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
=============== =============== =============== =============== == <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.ne tcom.com/> <

Jul 19 '05 #4

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

Similar topics

12
4456
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 characters as possible will be matched. the regular expression module fails to perform non-greedy matches as described in the documentation: more than "as few characters as possible"
5
3772
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 their dtor is called immediately and not at the end of the function. to be able to use return objects (to avoid copying) i often assign them to a const reference. now, casting a const return object from a function to a non-const reference to this...
25
7736
by: Yves Glodt | last post by:
Hello, if I do this: for row in sqlsth: ________pkcolumns.append(row.strip()) ________etc without a prior:
32
4568
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
8
3533
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 cannot load/unload/reload extensions into my large and slow-to-load application during development without restarting the process then the disadvantages may outweigh the advantages. I've got a mixed-mode program in which I create a new AppDomain...
14
8548
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
3485
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 vtable pointer is made use of.. eg. class one {
2
6147
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 pointers, but I'm not sure. Please help. The code: void equate(matrix *A, matrix *B) { int i, j; assert(A.row_dim == B.col_dim && A.col_dim == B.col_dim); for(i=0; i < A.row_dim; i++) for(j=0; j < A.col_dim; j++)
0
2357
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 jobs. When a non-secure page references a secure page with relative URL, the web server generates error until absolute URL with https prefix is used. On the other hand when a secure page references a non-secure page, the non-secure page will be...
399
13235
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 to python-3000@python.org In summary, this PEP proposes to allow non-ASCII letters as identifiers in Python. If the PEP is accepted, the following identifiers would also become valid as class, function, or variable names: Löffelstiel,...
0
10143
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11539
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10666
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9866
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7393
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6090
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6312
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4913
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4515
muto222
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.