def gc(self): now = time.time() for key, parser in self.parsers.items(): if parser.getLastMessageTime() < (now-config.getint('timers', 'idle_server_timeout')): del self.parsers[key] parser.stop() parser.join() pass
def garbageCollector(self): if self.locking: self.updateLock.acquire() prune_time = time.time() - config.getint('timers', 'gc_age') for index, value in self.cache.items(): if self.cache[index] is not None and self.cache[index]["_flushed"] >= self.cache[index]["_updated"] and self.cache[index]["_flushed"] < prune_time: for index_key in self.index_keys: if index_key in self.index and index_key in self.cache[index] and self.cache[index][index_key] in self.index[index_key]: self.index[index_key][self.cache[index][index_key]].discard(index) del(self.cache[index]) if self.locking: self.updateLock.release()
from twisted.internet.task import LoopingCall from twisted.web import static, server # Create the log server for UDP connections logserver = LogServer() logserver.config = config # Install SIGINT handler reactor.addSystemEventTrigger('before', 'shutdown', logserver.shutdown) # Setup Log Server reactor.listenUDP(27501, logserver) # Set Up Garbage Collector for log server gc = LoopingCall(logserver.gc) gc.start(config.getint('timers', 'idle_server_search_interval')) stats = LoopingCall(logserver.stats) stats.start(config.getint('timers', 'print_stats')) # Set up Model Garbage Collectors def model_gc(): Engine().garbageCollector() Game().garbageCollector() GamePlayer().garbageCollector() GameServer().garbageCollector() GameMap().garbageCollector() Player().garbageCollector() modelgc = LoopingCall(model_gc)