socket read timeout

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

    #1

    socket read timeout

    Hi,

    I am looking for the most efficient / cleanest way to implement a socket
    read with timeout (Windows mainly but would be great if the same code
    worked under *nix)

    Tanks,

    hg

  • Jarek Zgoda

    #2
    Re: socket read timeout

    hg napisa³(a):
    I am looking for the most efficient / cleanest way to implement a socket
    read with timeout (Windows mainly but would be great if the same code
    worked under *nix)
    Did you see http://www.timo-tasi.org/python/timeoutsocket.py ?

    --
    Jarek Zgoda

    "We read Knuth so you don't have to."

    Comment

    • Steve Holden

      #3
      Re: socket read timeout

      Jarek Zgoda wrote:
      hg napisa³(a):
      >
      >I am looking for the most efficient / cleanest way to implement a socket
      >read with timeout (Windows mainly but would be great if the same code
      >worked under *nix)
      >
      Did you see http://www.timo-tasi.org/python/timeoutsocket.py ?
      >
      Note that since 2.4, I believe, sockets in the standard library allow
      you to specify a timeout parameter.

      regards
      Steve
      --
      Steve Holden +44 150 684 7255 +1 800 494 3119
      Holden Web LLC/Ltd http://www.holdenweb.com
      Skype: holdenweb http://del.icio.us/steve.holden
      Recent Ramblings http://holdenweb.blogspot.com

      Comment

      • skip@pobox.com

        #4
        Re: socket read timeout

        >I am looking for the most efficient / cleanest way to implement a
        >socket read with timeout (Windows mainly but would be great if the
        >same code worked under *nix)
        JarekDid you see http://www.timo-tasi.org/python/timeoutsocket.py ?

        Also socket objects have timeout attributes now.

        Skip

        Comment

        • hg

          #5
          Re: socket read timeout

          Steve Holden wrote:
          Jarek Zgoda wrote:
          >hg napisa?(a):
          >>
          >>I am looking for the most efficient / cleanest way to implement a socket
          >>read with timeout (Windows mainly but would be great if the same code
          >>worked under *nix)
          >>
          >Did you see http://www.timo-tasi.org/python/timeoutsocket.py ?
          >>
          Note that since 2.4, I believe, sockets in the standard library allow
          you to specify a timeout parameter.
          >
          regards
          Steve
          --
          Steve Holden +44 150 684 7255 +1 800 494 3119
          Holden Web LLC/Ltd http://www.holdenweb.com
          Skype: holdenweb http://del.icio.us/steve.holden
          Recent Ramblings http://holdenweb.blogspot.com
          Hi and thanks to all.

          Do you mean use select ?

          Thanks,

          hg

          Comment

          • Facundo Batista

            #6
            Re: socket read timeout

            hg wrote:
            Do you mean use select ?
            No, socket's timeout:
            >>import socket
            >>s = socket.socket()
            >>s.settimeout( 5)
            >>...
            Regards,

            --
            .. Facundo
            ..
            Blog: http://www.taniquetil.com.ar/plog/
            PyAr: http://www.python.org/ar/


            Comment

            • hg

              #7
              Re: socket read timeout

              Facundo Batista wrote:
              hg wrote:
              >
              >Do you mean use select ?
              >
              No, socket's timeout:
              >
              >>>import socket
              >>>s = socket.socket()
              >>>s.settimeout (5)
              >>>...
              >
              Regards,
              >
              --
              . Facundo
              .
              Blog: http://www.taniquetil.com.ar/plog/
              PyAr: http://www.python.org/ar/

              My issue with that is the effect on write: I only want a timeout on read ...
              but anyway ...

              Thanks,

              hg


              Comment

              • Steve Holden

                #8
                Re: socket read timeout

                hg wrote:
                Facundo Batista wrote:
                >
                >hg wrote:
                >>
                >>Do you mean use select ?
                >No, socket's timeout:
                >>
                >>>>import socket
                >>>>s = socket.socket()
                >>>>s.settimeou t(5)
                >>>>...
                >Regards,
                >>
                >--
                >. Facundo
                >.
                >Blog: http://www.taniquetil.com.ar/plog/
                >PyAr: http://www.python.org/ar/
                >
                >
                My issue with that is the effect on write: I only want a timeout on read ...
                but anyway ...
                >
                If you want selective timeout behaviour then yes, you should use select.

                regards
                Steve
                --
                Steve Holden +44 150 684 7255 +1 800 494 3119
                Holden Web LLC/Ltd http://www.holdenweb.com
                Skype: holdenweb http://del.icio.us/steve.holden
                Recent Ramblings http://holdenweb.blogspot.com

                Comment

                • skip@pobox.com

                  #9
                  Re: socket read timeout


                  hgMy issue with that is the effect on write: I only want a timeout on
                  hgread ... but anyway ...

                  So set a long timeout when you want to write and short timeout when you want
                  to read.

                  Skip

                  Comment

                  • hg

                    #10
                    Re: socket read timeout

                    skip@pobox.com wrote:
                    >
                    hgMy issue with that is the effect on write: I only want a timeout
                    on
                    hgread ... but anyway ...
                    >
                    So set a long timeout when you want to write and short timeout when you
                    want to read.
                    >
                    Skip

                    Not bad .. thanks

                    Comment

                    • Hendrik van Rooyen

                      #11
                      Re: socket read timeout

                      <skip@p....x.co mwrote:

                      >
                      hgMy issue with that is the effect on write: I only want a timeout on
                      hgread ... but anyway ...
                      >
                      So set a long timeout when you want to write and short timeout when you want
                      to read.
                      >
                      Are sockets full duplex?

                      I know Ethernet isn't.

                      - Hendrik


                      Comment

                      • Damjan

                        #12
                        Re: socket read timeout

                        >So set a long timeout when you want to write and short timeout when you
                        >want to read.
                        >>
                        >
                        Are sockets full duplex?
                        >
                        I know Ethernet isn't.
                        Both are full duplex.

                        --
                        damjan

                        Comment

                        • Steve Holden

                          #13
                          Re: socket read timeout

                          Hendrik van Rooyen wrote:
                          <skip@p....x.co mwrote:
                          >
                          >
                          > hgMy issue with that is the effect on write: I only want a timeout on
                          > hgread ... but anyway ...
                          >>
                          >So set a long timeout when you want to write and short timeout when you want
                          >to read.
                          >>
                          >
                          Are sockets full duplex?
                          >
                          Yes. But you have to use non-blocking calls in your application to use
                          them as full-duplex in your code.
                          I know Ethernet isn't.
                          >
                          Don't know much, then, do you? ;-)

                          regards
                          Steve
                          --
                          Steve Holden +44 150 684 7255 +1 800 494 3119
                          Holden Web LLC/Ltd http://www.holdenweb.com
                          Skype: holdenweb http://del.icio.us/steve.holden
                          Recent Ramblings http://holdenweb.blogspot.com

                          Comment

                          • Hendrik van Rooyen

                            #14
                            Re: socket read timeout

                            "Steve Holden" <s..e@hol....eb .com>

                            Hendrik van Rooyen wrote:
                            <skip@p....x.co mwrote:

                            hgMy issue with that is the effect on write: I only want a timeout on
                            hgread ... but anyway ...
                            >
                            So set a long timeout when you want to write and short timeout when you
                            want
                            to read.
                            >
                            Are sockets full duplex?
                            Yes. But you have to use non-blocking calls in your application to use
                            them as full-duplex in your code.
                            This seems to bear out the scenario I have described elsewhere in this
                            thread - I think its caused by the file handlers, but I don't _know_ it.
                            >
                            I know Ethernet isn't.
                            Don't know much, then, do you? ;-)
                            No not really - I easily get confused by such things as collisions...

                            : - )

                            - Hendrik

                            Comment

                            • Bryan Olson

                              #15
                              Re: socket read timeout

                              Steve Holden wrote:
                              Hendrik van Rooyen wrote:
                              >Are sockets full duplex?
                              >>
                              Yes. But you have to use non-blocking calls in your application to use
                              them as full-duplex in your code.
                              Hmmm... I'm missing something. Suppose I have one thread (or
                              process) reading from a blocking-mode socket while another is
                              writing to it? What stops it from being full duplex?


                              --
                              --Bryan

                              Comment

                              Working...