[IronPython] poplib.POP3_SSL OutOfMemory Issue
dinov at microsoft.com
Wed Nov 18 11:00:10 PST 2009
It might be interesting to run w/ -X:ExceptionDetail to see where the OOM is actually coming from. It could be that there's one giant allocation which is failing or it could be that something's broken and causing a big loop which allocates forever. -X:ExceptionDetail might given an indication of which one it is.
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of matan keret
Sent: Sunday, November 15, 2009 8:34 AM
To: Discussion of IronPython
Subject: [IronPython] poplib.POP3_SSL OutOfMemory Issue
i wrote the next code which suppose to go to my hotmail account, fetch the last email's image attachment and save it to a file:
import email, poplib, os, string
items = 
for message in message_list:
message_parts = string.split(message,' ')
message_id = message_parts
# print 'message id is: %s\n' % message_id
# print 'done getting ids'
host = "pop3.live.com<http://pop3.live.com>"
detach_dir = 'D:\\test-attachments\\' # directory where to save attachments (default: current)
user = "matan.py at hotmail.com<mailto:matan.py at hotmail.com>"
pwd = "0okmnji9"
server = poplib.POP3_SSL(host)
numMessages = len(server.list())
# server.list() returns messages info from server in
# form of response, message_list, size where message_list
# is. a list of messages in form of 'message_id size'
message_list = server.list()
# get the list of items id
items = get_messages_id(message_list)
items.reverse() # puts the last received mail's id in the first place in list
is_image = False
# find the first mail in items that has an attachment and get the attachment
for emailid in items:
# if we found an email with an image we break
total_email_message = server.retr(emailid)
messageText = string.join(total_email_message, "\n")
mail = email.message_from_string(messageText) # parsing the mail content to get a mail object
# Check if there are any attachments at all
if mail.get_content_maintype() != 'multipart':
# we use walk to create a generator so we can iterate on the parts
for part in mail.walk():
# skip any attachment which is not an image
if part.get_content_maintype() != 'image':
# is this part an attachment ?
if part.get('Content-Disposition') is None:
filename = part.get_filename()
is_image = True
# if there is no filename, we create one with a counter to avoid duplicates
if not filename:
filename = 'part-%03d%s' % (1, 'bin')
att_path = os.path.join(detach_dir, filename)
# Check if its not already there and finally write the file
if not os.path.isfile(att_path) :
fp = open(att_path, 'wb')
# if we found an email with an image we break after first image downloaded
print 'Finished fetching the image'
# THE END
also available at: http://pastebin.org/53873
This works fine on Cpython but on IronPython 2.0.3 I get:
Traceback (most recent call last):
File "get_first_attachment.py", line 21, in get_first_attachment.py
File "D:\IronPython 2.0.3\Lib\poplib.py", line 361, in __init__
File "D:\IronPython 2.0.3\Lib\poplib.py", line 137, in _getresp
File "D:\IronPython 2.0.3\Lib\poplib.py", line 374, in _getline
File "D:\IronPython 2.0.3\Lib\poplib.py", line 364, in _fillBuffer
MemoryError: Exception of type 'System.OutOfMemoryException' was thrown.
this comes out from line 21:
server = poplib.POP3_SSL(host)
Any ideas why is that? How to fix it? Is it a known issue (tried to look but couldn't find)?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Users