def _expire_sessions(self): while self._is_active: try: self._remove_inactive_sessions() except Exception as e: logger.error('Error in session expiration thread: %s' % e) time.sleep(3.0)
def handle_request(self, rh): request = MgtMessage() request.load(rh.input_buffer) cmd = request.header try: args = self.execute_command(cmd, request) if args: response = MgtMessage(*args) # send the response rh.write_buffer(response.serialize()) except: logger.error('Management Error:', *(), **{'exc_info': 1}) error_msg = MgtMessage(-1, 'Internal server error. See server log for details.') rh.write_buffer(error_msg.serialize())
def _expire_sessions(self): from porcupine.core.runtime import logger while self._is_active: try: # get inactive sessions cursor = db._db.join(( ('_parentid', '_sessions'), ('modified', (None, time.time() - self.timeout))), None) cursor.fetch_all = True sessions = [session for session in cursor] cursor.close() for session in sessions: logger.debug('Expiring Session: %s' % session.id) session.terminate() except Exception, e: logger.error('Error in session expiration thread: %s' % e) time.sleep(3.0)