IMAP4 example in docs causes memory error for me (OS X 10.3,
steven alyari
ossix at ossix.net
Sat Nov 13 19:20:35 EST 2004
John,
I have the same problem with OS X and Python 2.3 standard.
the code:
import getpass, imaplib
M = imaplib.IMAP4("mail.host")
M.login(getpass.getuser(), getpass.getpass())
M.select( )
typ, data = M.search(None, 'ALL')
mydir = "./msgs"
i = 0
for num in data[0].split( ):
print str(i) + " ..."
typ, data = M.fetch(num, '(RFC822)')
w = file(mydir + "/" + str(i) + ".msg","w")
w.write(data[0][1])
w.close( )
i+=1
M.logout( )
one the 115th message i get this error:
*** malloc: vm_allocate(size=4755456) failed (error code=3)
*** malloc[1471]: error: Can't allocate region
Traceback (most recent call last):
File "imap.py", line 13, in ?
typ, data = M.fetch(num, '(RFC822)')
File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/imaplib.py", line 417, in fetch
typ, dat = self._simple_command(name, message_set, message_parts)
File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/imaplib.py", line 1000, in _simple_command
return self._command_complete(name, self._command(name, *args))
File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/imaplib.py", line 830, in _command_complete
typ, data = self._get_tagged_response(tag)
File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/imaplib.py", line 931, in _get_tagged_response
self._get_response()
File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/imaplib.py", line 893, in _get_response
data = self.read(size)
File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/imaplib.py", line 231, in read
return self.file.read(size)
File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/socket.py", line 301, in read
data = self._sock.recv(recv_size)
MemoryError
Thanks,
Steven Alyari
>
>
> I am running the IMAP4 example in the documentation:
>
> http://www.python.org/doc/lib/imap4-example.html
>
> with two small changes (different username, comment out print
> statement). The inbox I am accessing is 42 MB and has 80-someodd
> messages, so the messages are fairly big (all of them have
> attachments). When I run this program, I get a malloc error. Now, I'm
> really new to python programming, but it was my understanding that
> memory management was not something I had to explicitly do. I'd
> appreciate some help in understanding what I've done wrong.
>
> If I watch memory usage via "top", the memory usage (vmem) goes up to
> 3.5 GB, drops back down to a few tens of megabytes, then rises to 3.5
> GB or so again, then crashes. (Backtrace is appended at the end of
> this message.) It seems odd to me that python should require GB of
> memory to read a 40 MB mailbox.
>
> I also installed python 2.3.3 via fink and was able to reproduce the
> error in the same way.
>
> Machine / python information:
>
> [JDO:~/Documents/src/vm2imap] jowens% uname -a
> Darwin JDO.local 7.5.0 Darwin Kernel Version 7.5.0: Thu Aug 5
> 19:26:16 PDT 2004; root:xnu/xnu-517.7.21.obj~3/RELEASE_PPC Power
> Macintosh powerpc
> [JDO:~/Documents/src/vm2imap] jowens% python -V
> Python 2.3.3
>
> JDO
>
> ==
>
> *** malloc: vm_allocate(size=7426048) failed (error code=3)
> *** malloc[17319]: error: Can't allocate region
> Traceback (most recent call last):
> File "minimal.py", line 8, in ?
> typ, data = M.fetch(num, '(RFC822)')
> File "/sw/lib/python2.3/imaplib.py", line 417, in fetch
> typ, dat = self._simple_command(name, message_set, message_parts)
> File "/sw/lib/python2.3/imaplib.py", line 1000, in _simple_command
> return self._command_complete(name, self._command(name, *args))
> File "/sw/lib/python2.3/imaplib.py", line 830, in _command_complete
> typ, data = self._get_tagged_response(tag)
> File "/sw/lib/python2.3/imaplib.py", line 931, in
> _get_tagged_response
> self._get_response()
> File "/sw/lib/python2.3/imaplib.py", line 893, in _get_response
> data = self.read(size)
> File "/sw/lib/python2.3/imaplib.py", line 231, in read
> return self.file.read(size)
> File "/sw/lib/python2.3/socket.py", line 301, in read
> data = self._sock.recv(recv_size)
> MemoryError
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 4659 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20041113/584047e9/attachment.bin>
More information about the Python-list
mailing list