check if there is data in stdin without blocking

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hg

    #1

    check if there is data in stdin without blocking

    Hi,

    Is there a way ? ... select ?



    hg

  • hg

    #2
    Re: check if there is data in stdin without blocking

    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


    Comment

    • Laurent Pointal

      #3
      Re: check if there is data in stdin without blocking

      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.s elect)
      ....<zip>...
      *** IMPORTANT NOTICE ***
      On Windows, only sockets are supported; on Unix, all file descriptors.



      If under Unix, maybe sys.stdin.filen o() 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.

      Comment

      • hg

        #4
        Re: check if there is data in stdin without blocking

        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.filen o() 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





        Comment

        • Paul Boddie

          #5
          Re: check if there is data in stdin without blocking

          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

          Comment

          • hg

            #6
            Re: check if there is data in stdin without blocking

            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


            Comment

            • Gabriel Genellina

              #7
              Re: check if there is data in stdin without blocking

              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.activestat e.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!


              Comment

              • hg

                #8
                Re: check if there is data in stdin without blocking

                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.activestat e.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

                Comment

                Working...