From 9c678c9d6baee266c4772a4c197cd35ceb00ebc8 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Tue, 6 Sep 2011 13:19:25 +0200 Subject: [PATCH] Allow Imapserver.releaseconnection() to drop a connection 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 Signed-off-by: Nicolas Sebrecht --- offlineimap/imapserver.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py index e630f83..05d8111 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)