Charles-Francois Natali <neolo...@free.fr> added the comment: $ cat /tmp/test.py import socket
SIZE = 1000000000L s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) try: s.recv(SIZE) finally: s.close() $ python /tmp/test.py Traceback (most recent call last): File "/tmp/test.py", line 8, in <module> s.recv(SIZE) MemoryError $ strace python /tmp/test.py [...] socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3 mmap2(NULL, 1000001536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -1 ENOMEM (Cannot allocate memory) brk(0x4440c000) = 0x8a56000 mmap2(NULL, 1000132608, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -1 ENOMEM (Cannot allocate memory) mmap2(NULL, 2097152, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0) = 0xb79b1000 munmap(0xb79b1000, 323584) = 0 munmap(0xb7b00000, 724992) = 0 mprotect(0xb7a00000, 135168, PROT_READ|PROT_WRITE) = 0 mmap2(NULL, 1000001536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -1 ENOMEM (Cannot allocate memory) [...] imaplib is simply requesting too much at a time: the memory error is probably raised in Modules/socketmodule.c:sock_recv /* Allocate a new string. */ buf = PyString_FromStringAndSize((char *) 0, recvlen); if (buf == NULL) return NULL; Requesting a 10M read is indeed quite questionable, and will fail no matter what system is used (the limit will depend on the heap usage and OS, though). The fix should be made at imaplib level, rather than requiring users to redefine IMAP4 read method. A patch is attached (imaplib_read.diff). ---------- keywords: +patch nosy: +neologix Added file: http://bugs.python.org/file16747/imaplib_read.diff _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue1441530> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com