parameters: (self)
docstring: Clean up expired sessions.
docstring_summary: Clean up expired sessions.
docstring_tokens: Clean up expired sessions .
function: def clean_up(self):
          """Clean up expired sessions."""
          now = self.now()
          # Iterate over all session files in self.storage_path
          for fname in os.listdir(self.storage_path):
              have_session = (
                  fname.startswith(self.SESSION_PREFIX)
                  and not fname.endswith(self.LOCK_SUFFIX)
              )
              if have_session:
                  # We have a session file: lock and load it and check
                  #   if it's expired. If it fails, nevermind.
                  path = os.path.join(self.storage_path, fname)
                  self.acquire_lock(path)
                  if self.debug:
                      # This is a bit of a hack, since we're calling clean_up
                      # on the first instance rather than the entire class,
                      # so depending on whether you have "debug" set on the
                      # path of the first session called, this may not run.
                      cherrypy.log('Cleanup lock acquired.', 'TOOLS.SESSIONS')
  
                  try:
                      contents = self._load(path)
                      # _load returns None on IOError
                      if contents is not None:
                          data, expiration_time = contents
                          if expiration_time < now:
                              # Session expired: deleting it
                              os.unlink(path)
                  finally:
                      self.release_lock(path)
function_tokens: def clean_up ( self ) : now = self . now ( ) # Iterate over all session files in self.storage_path for fname in os . listdir ( self . storage_path ) : have_session = ( fname . startswith ( self . SESSION_PREFIX ) and not fname . endswith ( self . LOCK_SUFFIX ) ) if have_session : # We have a session file: lock and load it and check #   if it's expired. If it fails, nevermind. path = os . path . join ( self . storage_path , fname ) self . acquire_lock ( path ) if self . debug : # This is a bit of a hack, since we're calling clean_up # on the first instance rather than the entire class, # so depending on whether you have "debug" set on the # path of the first session called, this may not run. cherrypy . log ( 'Cleanup lock acquired.' , 'TOOLS.SESSIONS' ) try : contents = self . _load ( path ) # _load returns None on IOError if contents is not None : data , expiration_time = contents if expiration_time < now : # Session expired: deleting it os . unlink ( path ) finally : self . release_lock ( path )