[Zope] Memorysegment error in Zope

Max M maxm at mxm.dk
Tue Apr 26 02:01:16 EDT 2005


I am writing an Imap client. The Imap server (Groupwise) I connect to is 
really slow at accepting logins.

So I have made a connection pool where I store the open connections to 
the server.

But once in a while I get a memory segment error on the server and it 
crashes.

I suspect what happens is that a connection has been idle for to long, 
ad the connection dropped by the imap server. Which might cause some 
memory to be freed that is then accessed when I call noop().

It could also be be some kind of threading problem.

Does any of you hav an ide as to how I can find out? I am not used to 
these kind of problems, having been spoiled by Python for too long.

regards Max M


I have attached the connection pool code in the bottom.


##########################################
# a borg/singleton for pooling connections.
# Necessary as login can take a looong time

class ConnectionPool:

     __shared_state = {}

     def __init__(self):
         self.__dict__ = self.__shared_state

     def getConnection(self, server_uri, user, password):
         if not hasattr(self, 'connections'):
             self.connections = {}
         user_key = (server_uri, user, password)
         user_connections = self.connections.setdefault(user_key, [])
         # first try and return a connection from the pool
         for i in range(len(user_connections)-1, -1, -1):
             # a connection can be timed out,
             # try noop to see if it's still open
             connection = user_connections[i]
             try:
                 connection.noop()
                 return user_connections.pop(i)
             except: # else login again
                 user_connections.pop(i)
         # if no usable connections in the pool,
         # create new one and return it
         return Imap4Connector(server_uri, user, password)


     def release(self, connection):
         # take the connection and put it in the pool
         user_key = (connection.server_uri, connection.user, \ 

                     connection.password)
         user_connections = self.connections.setdefault(user_key, [])
         user_connections.append(connection)


-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science



More information about the Zope mailing list