[PATCH 1/2] Allow Imapserver.releaseconnection() to drop a connection
Sebastian Spaeth
Sebastian at SSpaeth.de
Tue Sep 6 12:19:25 BST 2011
If a connection is broken, we want to have it really dropped and not be
reused. So far, we are checking the .Terminate attribute for this, but
according to the imaplib2 author, it is only set on normal shutdown and
it is an undocumented attribute whose meaning could change any time.
This patch introduces the parameter drop_conn which allows to tell
releaseconnection() that we really want to connection being dropped from
the pool of available connections and properly destroy it.
Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
offlineimap/imapserver.py | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py
index 3ce751c..88d3b29 100644
--- a/offlineimap/imapserver.py
+++ b/offlineimap/imapserver.py
@@ -109,12 +109,15 @@ class IMAPServer:
return self.root
- def releaseconnection(self, connection):
- """Releases a connection, returning it to the pool."""
+ def releaseconnection(self, connection, drop_conn=False):
+ """Releases a connection, returning it to the pool.
+
+ :param drop_conn: If True, the connection will be released and
+ not be reused. This can be used to indicate broken connections."""
self.connectionlock.acquire()
self.assignedconnections.remove(connection)
# Don't reuse broken connections
- if connection.Terminate:
+ if connection.Terminate or drop_conn:
connection.logout()
else:
self.availableconnections.append(connection)
--
1.7.4.1
More information about the OfflineIMAP-project
mailing list