check if there is data in stdin without blocking

H

hg

hg said:
Hi,

Is there a way ? ... select ?



hg
PS:

import sys
import select

l_r = select.select([sys.stdin],[],[],0)

gives me:
File "select.py", line 2, in ?
import select
File "/home/philippe/Desktop/select.py", line 4, in ?
l_r = select.select([sys.stdin],[],[],0)
TypeError: 'module' object is not callable
 
H

hg

Laurent said:
hg a écrit :
hg said:
Hi,

Is there a way ? ... select ?



hg
PS:

import sys
import select

l_r = select.select([sys.stdin],[],[],0)

gives me:
File "select.py", line 2, in ?
import select
File "/home/philippe/Desktop/select.py", line 4, in ?
l_r = select.select([sys.stdin],[],[],0)
TypeError: 'module' object is not callable

Wont work under Windows:...<zip>...
*** IMPORTANT NOTICE ***
On Windows, only sockets are supported; on Unix, all file descriptors.



If under Unix, maybe sys.stdin.fileno() is a valid descriptor for
select. Just test it.

And if under Windows, you may take a look at
22.1 msvcrt - Useful routines from the MS VC++ runtime
22.1.2 Console I/O
kbhit( ) - Return true if a keypress is waiting to be read.


Well I'm testing under Linux but need support under Windows ... is there any
way to poll stdin somehow under both plateform ?

thanks,

hg
 
H

hg

Paul said:
hg said:
import select
[...]

File "/home/philippe/Desktop/select.py", line 4, in ?

Consider which module Python is trying to import here: the standard
library select module or your own program?

Paul

Argh !!!! ;-)



thanks
 
L

Laurent Pointal

hg a écrit :
hg said:
Hi,

Is there a way ? ... select ?



hg
PS:

import sys
import select

l_r = select.select([sys.stdin],[],[],0)

gives me:
File "select.py", line 2, in ?
import select
File "/home/philippe/Desktop/select.py", line 4, in ?
l_r = select.select([sys.stdin],[],[],0)
TypeError: 'module' object is not callable

Wont work under Windows:....<zip>...
*** IMPORTANT NOTICE ***
On Windows, only sockets are supported; on Unix, all file descriptors.



If under Unix, maybe sys.stdin.fileno() is a valid descriptor for
select. Just test it.

And if under Windows, you may take a look at
22.1 msvcrt - Useful routines from the MS VC++ runtime
22.1.2 Console I/O
kbhit( ) - Return true if a keypress is waiting to be read.
 
P

Paul Boddie

hg said:
import select
[...]

File "/home/philippe/Desktop/select.py", line 4, in ?

Consider which module Python is trying to import here: the standard
library select module or your own program?

Paul
 
G

Gabriel Genellina

Well I'm testing under Linux but need support under Windows ... is there any
way to poll stdin somehow under both plateform ?

I think you may want this portable getch function:
<http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/134892>


--
Gabriel Genellina
Softlab SRL






__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top