from DCHub import DCHub, run class PrivateDCHub(DCHub): '''Hub allowing only users with valid accounts If a user does not have a valid account, they are denied access to the hub. ''' def setupdefaults(self, **kwargs): super(PrivateDCHub, self).setupdefaults(**kwargs) self.supers['PrivateDCHub'] = super(PrivateDCHub, self) self.reloadmodules.append('PrivateDCHub') def checkValidateNick(self, user, nick): '''Don't allow logins without a valid account''' if nick not in self.accounts: raise ValueError, 'nick not a valid account' self.supers['PrivateDCHub'].checkValidateNick(user, nick) if __name__ == '__main__': run(PrivateDCHub)
finally: self.waitingtaskrunners -= 1 try: self.handletask(task) except: self.log.exception( 'Serious error in thread %i while handling task %s' % (tid, strtask)) else: self.log.log( self.loglevels['threading'], 'Thread %i executed task %s without raising an exception' % (tid, strtask)) finally: self.activetaskrunners -= 1 self.taskrunnerclose() self.log.log(self.loglevels['threading'], 'Thread %i exiting' % tid) def taskrunnerclose(self): '''Preform the necessary actions on thread shutdown''' del self.threaddata[threadid()] def taskrunnerinit(self): '''Preform the necessary actions on thread startup''' self.threaddata[threadid()] = {} if __name__ == '__main__': run(ThreadedDCHub)
while self.activetaskrunners < self.numtaskrunners + 1 and not self.exittaskrunner: self.waitingtaskrunners += 1 try: self.log.log(self.loglevels['threading'], 'Thread %i waiting for tasks' % tid) task = self.tasks.get(block=True) strtask = str(task) self.log.log(self.loglevels['threading'], 'Thread %i got task %s' % (tid, strtask)) finally: self.waitingtaskrunners -= 1 try: self.handletask(task) except: self.log.exception('Serious error in thread %i while handling task %s' % (tid, strtask)) else: self.log.log(self.loglevels['threading'], 'Thread %i executed task %s without raising an exception' % (tid, strtask)) finally: self.activetaskrunners -= 1 self.taskrunnerclose() self.log.log(self.loglevels['threading'], 'Thread %i exiting' % tid) def taskrunnerclose(self): '''Preform the necessary actions on thread shutdown''' del self.threaddata[threadid()] def taskrunnerinit(self): '''Preform the necessary actions on thread startup''' self.threaddata[threadid()] = {} if __name__ == '__main__': run(ThreadedDCHub)