def cmd_reload(self, user, target, params): if not self.bot.is_admin(user): return False self.log('Will reload all modules') mem_before = meminfo.memory() memory, names, failed, total = {}, [], 0, 0 for channel in self.bot.channels: memory[channel] = [] for module in self.bot.channels[channel]['modules'][:]: if module.name == self.name: continue memory[channel].append(module.name) if not names.count(module.name): names.append(module.name) module._shutdown() self.bot.channels[channel]['modules'].remove(module) for name in names: self.log('Reloading module %s' % name) m = __import__('%s' % name, globals(), locals(), ['*']) total += 1 try: reload(m) except: traceback.print_exc() failed += 1 onload = self.bot.config['onload'] for channel in onload['channels']: for module in onload['channels'][channel]['modules']: if module == self.name: continue total += 1 try: c = classloader._get_class('modules.%s.Module' % module) m = c(self.bot, channel) self.bot.channels[channel]['modules'].append(m) except: traceback.print_exc() failed += 1 mem_after = meminfo.memory() if mem_after > mem_before: mem_msg = 'Memory increased by %d bytes.' % \ (mem_after - mem_before) elif mem_after < mem_before: mem_msg = 'Memory decreased by %d bytes.' % \ (mem_before - mem_after) else: mem_msg = 'Memory didn\'t change.' self.log('Reloading modules finished. %s' % mem_msg) self.chanmsg('Reload done. %s' % mem_msg)
def memend(self, mem_before): mem_after = meminfo.memory() if mem_after > mem_before: mem_msg = 'Memory increased by %d bytes.' % \ (mem_after - mem_before) elif mem_after < mem_before: mem_msg = 'Memory decreased by %d bytes.' % \ (mem_before - mem_after) else: mem_msg = 'Memory didn\'t change.' print mem_msg
def cmd_mem(self, user, channel, params): mem = locale.format('%.*f', (0, float(meminfo.memory())), True) self.chanmsg('I\'m using %s bytes of memory' % mem)
def memstart(self): return meminfo.memory()