From: Piers L. <pi...@ja...> - 2012-11-14 01:30:45
|
On Tue, 13 Nov 2012 15:06:18 -0500, Dave Abrahams wrote: > > > Check it out. The first run is with imaplib2, the second with imaplib. > > --8<---------------cut here---------------start------------->8--- > pluto:~ dave% time python -c 'from imaplib2 import *; s = IMAP4_stream("/opt/local/libexec/dovecot/imap"); s.open(); s.select("INBOX")' > imap(dave): Info: Connection closed in=20 out=721 > imap(dave): Info: Connection closed in=18 out=694 > python -c 0.04s user 0.02s system 0% cpu 30.159 total > pluto:~ dave% time python -c 'from imaplib import *; s = IMAP4_stream("/opt/local/libexec/dovecot/imap"); s.open(); s.select("INBOX")' > imap(dave): Info: Connection closed in=20 out=721 > imap(dave): Info: Connection closed in=18 out=694 > python -c 0.04s user 0.02s system 64% cpu 0.086 total > --8<---------------cut here---------------end--------------->8--- > > If I don't try to open(), it goes fast: > > --8<---------------cut here---------------start------------->8--- > pluto:~ dave% time python -c 'from imaplib2 import *; print IMAP4_stream("/opt/local/libexec/dovecot/imap").select("INBOX")' > ('OK', ['44']) > imap(dave): Info: Connection closed in=38 out=1070 > python -c 0.04s user 0.02s system 34% cpu 0.161 total > --8<---------------cut here---------------end--------------->8--- Hi Dave, Actually, I'm surprised it finishes at all. Calling "open" is redundant immediately after instantiation, as open is already called in __init__. So you are opening two simultaneous streams here. The differences between imaplib and imaplib2 under these circumstances are probably due to the use of threading in the second, but I'm only guessing. So your second run above is the correct usage. Hope that helps. Piers Lauder |