check if there is data in stdin without blocking

Discussion in 'Python' started by hg, Jan 15, 2007.

  1. hg

    hg Guest

    Hi,

    Is there a way ? ... select ?



    hg
    hg, Jan 15, 2007
    #1
    1. Advertising

  2. hg

    hg Guest

    hg wrote:

    > 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
    hg, Jan 15, 2007
    #2
    1. Advertising

  3. hg

    hg Guest

    Laurent Pointal wrote:

    > hg a écrit :
    >> hg wrote:
    >>
    >>> 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:
    >>>> help(select.select)

    > ...<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
    hg, Jan 15, 2007
    #3
  4. hg

    hg Guest

    Paul Boddie wrote:

    > hg wrote:
    >> 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
    hg, Jan 15, 2007
    #4
  5. hg

    hg Guest

    Gabriel Genellina wrote:

    > At Monday 15/1/2007 05:55, hg wrote:
    >
    >>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


    will take a look, thanks.

    hg
    hg, Jan 15, 2007
    #5
  6. hg a écrit :
    > hg wrote:
    >
    >> 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:
    >>> help(select.select)

    ....<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.
    Laurent Pointal, Jan 15, 2007
    #6
  7. hg

    Paul Boddie Guest

    hg wrote:
    > 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
    Paul Boddie, Jan 15, 2007
    #7
  8. At Monday 15/1/2007 05:55, hg wrote:

    >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
    Gabriel Genellina, Jan 15, 2007
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hendra Gunawan
    Replies:
    1
    Views:
    12,510
    Allan Herriman
    Apr 8, 2004
  2. Voronkov Konstantin
    Replies:
    1
    Views:
    345
    John Harrison
    Oct 1, 2004
  3. Jakob Bieling
    Replies:
    1
    Views:
    2,988
    Rolf Magnus
    May 8, 2005
  4. Voronkov Konstantin
    Replies:
    2
    Views:
    562
    Richard Bos
    Oct 1, 2004
  5. Voronkov Konstantin
    Replies:
    3
    Views:
    318
    Richard Bos
    Oct 4, 2004
Loading...

Share This Page