[issue1441530] socket read() can cause MemoryError in Windows

Iain MacKay report at bugs.python.org
Tue Sep 2 19:52:37 CEST 2008


Iain MacKay <iain at computable-functions.com> added the comment:

Knowing that the large read provokes the problem enables one to write
this simple workaround by subclassing IMAP4 without patching the library:

maxRead = 1000000
class MySSL (imaplib.IMAP4_SSL):
  def read (self, n):
    #print "..Attempting to read %d bytes" % n
      if n <= maxRead:
        return imaplib.IMAP4_SSL.read (self, n)
      else:
        soFar = 0
        result = ""
        while soFar < n:
          thisFragmentSize = min(maxRead, n-soFar)
          #print "..Reading fragment size %s" % thisFragmentSize
          fragment =\
            imaplib.IMAP4_SSL.read (self, thisFragmentSize)
          result += fragment
          soFar += thisFragmentSize # only a few, so not a tragic o/head
          return result				

and this works just fine.

----------
nosy: +anglocelt
versions: +Python 2.5 -Python 2.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue1441530>
_______________________________________


More information about the Python-bugs-list mailing list