[Tutor] Too many open files -- how to copy a folder?
Kent Johnson
kent_johnson at skillsoft.com
Fri Oct 29 18:56:19 CEST 2004
another = [x for x in box]
This creates a list of all the messages in box. Apparently each message
wraps an open file, that is why you are getting the IOError.
My guess is that somewhere later in your program you say
for msg in another:
# do something with msg
If I am right, you can rewrite your program to iterate directly over the
mailbox, like this:
for msg in box:
# do something with msg
This form avoids creating a list with all the messages in it. Only one
message is active at a time and you will avoid the IOError.
Kent
At 06:55 PM 10/28/2004 -0400, Matej Cepl wrote:
>Hi,
>
>I've tried this:
>
>blahoslav:matej$ python
>Python 2.3.4 (#2, Sep 24 2004, 08:39:09)
>[GCC 3.3.4 (Debian 1:3.3.4-12)] on linux2
>Type "help", "copyright", "credits" or "license" for more information.
> >>> import mailbox
> >>> box = mailbox.Maildir("/home/matej/WP/trash/")
> >>> another = [x for x in box]
>Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "/usr/lib/python2.3/mailbox.py", line 246, in next
>IOError: [Errno 24] Too many open files:
>'/home/matej/WP/trash/cur/1098844013.6284.XKuCF:2,S'
>
>Can be done something about that? Of course, that I will use some filter in
>the mapping, but still even when I try
>
> >>> import email,email.Utils
> >>> import mailbox
> >>> box = mailbox.Maildir("/home/matej/WP/trash/")
> >>> date = email.Utils.parsedate_tz
> >>> import time
> >>> dlist = list(time.localtime())
> >>> dlist[1] -= 3
> >>> archdate = tuple(dlist)
> >>> alist = [x for x in box if date(x['date'])<archdate]
>Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "/usr/lib/python2.3/mailbox.py", line 246, in next
>IOError: [Errno 24] Too many open files:
>'/home/matej/WP/trash/cur/1098844013.6284.XKuCF:2,S'
> >>>
>
>I don't get too far (and the folder is not that extreme -- 1333 messages).
>Any thoughts?
>
>Matej
>
>
>--
>Matej Cepl, http://www.ceplovi.cz/matej
>GPG Finger: 89EF 4BC6 288A BF43 1BAB 25C3 E09F EF25 D964 84AC
>138 Highland Ave. #10, Somerville, Ma 02143, (617) 623-1488
>
>I have never killed a man, but I have read many obituaries with
>great pleasure.
> -- Clarence Darrow
>
>
>
>_______________________________________________
>Tutor maillist - Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list