[Tutor] Finding an object by ID

Dj Gilcrease digitalxero at gmail.com
Wed May 2 23:13:52 CEST 2007


I was wondering if it was possible to find and object by it's ID.

what I want to do is something like

def incomingConnection(self, stuff):
    (incSock, incAdder) = self.__sock.accept()

    #Add the adder socket ID and other info to a DB

def sendMessage(self, adder, message):
    #query the DB and get the socket ID stored there

    sock = getSocketByID(sockID)

    #do my send data



The reason I want to do this is right now I store all the data in a
dict of class

eg
class connections:
    def __init__(self, *args, **kwargs):
        self.sock = args[0]
        self.myotherdata = stuff
        ...


def incomingConnection(self, stuff):
    (incSock, incAdder) = self.__sock.accept()
    self.conns[incAdder] = connections(incSock, ...)


This takes up about 20 megs per person connecting, which is very high
IMHO, and I am hoping by storing all the data in the database and only
retrieving it when I need it will help reduce the memory footprint of
my server


More information about the Tutor mailing list