#5 Fix for bug 1043420 (OSError: EAGAIN)

closed-accepted
nobody
None
5
2004-11-13
2004-10-09
No

Fix for bug 1043420 (OSError: EAGAIN)

Discussion

  • Chris Liechti

    Chris Liechti - 2004-11-13
    • status: open --> closed-accepted
     
  • Nobody/Anonymous

    Logged In: NO

    This patch will peak my CPU at 100% if I send a large string
    out. I did a minor change to the patch.

    --- serialposix.py-orig 2004-10-08 22:25:15.049576526 -0500
    +++ serialposix.py 2004-10-08 22:22:07.506545359 -0500
    @@ -5,17 +5,17 @@
    #

    #(C) 2001-2003 Chris Liechti <cliechti@gmx.net>

    # this is distributed under a free software license, see
    license.txt

    #

    #parts based on code from Grant B. Edwards <grante@visi.com>:

    # ftp://ftp.visi.com/users/grante/python/PosixSerial.py

    # references: http://www.easysw.com/~mike/serial/serial.html

    -import sys, os, fcntl, termios, struct, select

    +import sys, os, fcntl, termios, struct, select, errno, time

    from serialutil import *

    VERSION = "$Revision: 1.23 $".split()[1] #extract CVS
    version

    #Do check the Python version as some constants have moved.

    if (sys.hexversion < 0x020100f0):

    import TERMIOS

    else:

    @@ -276,27 +276,33 @@
    return read

    def write(self, data):

    """Output the given string over the serial port."""

    if self.fd is None: raise portNotOpenError

    t = len(data)

    d = data

    while t > 0:

    - if self._writeTimeout is not None and
    self._writeTimeout > 0:

    - _,ready,_ = select.select([],[self.fd],[],
    self._writeTimeout)

    - if not ready:

    - raise writeTimeoutError

    - n = os.write(self.fd, d)

    - if self._writeTimeout is not None and
    self._writeTimeout > 0:

    - _,ready,_ = select.select([],[self.fd],[],
    self._writeTimeout)

    - if not ready:

    - raise writeTimeoutError

    - d = d[n:]

    - t = t - n

    + try:

    + if self._writeTimeout is not None and
    self._writeTimeout > 0:

    + _,ready,_ =
    select.select([],[self.fd],[], self._writeTimeout)

    + if not ready:

    + raise writeTimeoutError

    + n = os.write(self.fd, d)

    + if self._writeTimeout is not None and
    self._writeTimeout > 0:

    + _,ready,_ =
    select.select([],[self.fd],[], self._writeTimeout)

    + if not ready:

    + raise writeTimeoutError

    + d = d[n:]

    + t = t - n

    + except OSError,v:

    + if v.errno != errno.EAGAIN:

    + raise

    + time.sleep(0.001)

    +

    def flush(self):

    """Flush of file like objects. In this case, wait
    until all data

    is written."""

    self.drainOutput()

    def flushInput(self):

    """Clear input buffer, discarding all that is in
    the buffer."""

     

Log in to post a comment.