Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Ticket #717: session_len.patch

  • cherrypy/__init__.py

    old new  
    267267    def __contains__(self, key): 
    268268        child = getattr(serving, self.__attrname__) 
    269269        return key in child 
     270         
     271    def __len__(self): 
     272        child = getattr(serving, self.__attrname__) 
     273        return len(child) 
    270274 
    271275 
    272276# Create request and response object (the same objects will be used 
  • cherrypy/lib/sessions.py

    old new  
    233233    def release_lock(self): 
    234234        self.locks[self.id].release() 
    235235        self.locked = False 
     236         
     237    def __len__(self): 
     238        "Returns number of active sessions" 
     239        return len(self.cache) 
    236240 
    237241 
    238242class FileSession(Session): 
     
    328332                            os.unlink(path) 
    329333                finally: 
    330334                    self.release_lock(path) 
     335     
     336    def __len__(self): 
     337        "Returns number of active sessions" 
     338        sessions = os.listdir(self.storage_path) 
     339        sessions = [fname for fname in sessions if (fname.startswith(self.SESSION_PREFIX) and not fname.endswith(self.LOCK_SUFFIX))] 
     340        return len(sessions) 
     341         
     342         
    331343 
    332344 
    333345class PostgresqlSession(Session): 

Hosted by WebFaction

Log in as guest/cpguest to create tickets