From: Santhosh T. <san...@gm...> - 2011-03-05 13:19:05
|
Hi, I have a python xmpp bot with nearly 10000 users. When the user count reached at this level, my messageHandler is not getting invoked. Putting it in debug mode shows that PresenceHandler is eating up all the loop cycles. This is the relevant code snippets class Bot: """ The main bot class. """ def __init__(self, JID, Password): """ Create a new bot. Connect to the server and log in. """ # connect... jid = xmpp.JID(JID) self.connection = xmpp.Client(jid.getDomain(), debug=[]) [ ......] self.connection.RegisterHandler('presence',self.presenceHandler) self.connection.RegisterHandler('message',self.messageHandler) def loop(self): """ Do nothing except handling new xmpp stanzas. """ try: while self.connection.Process(1): pass except KeyboardInterrupt: pass def presenceHandler(self, conn, presence): '''Auto authorizing chat invites''' if presence: if presence.getType() == 'subscribe': jabber_id = presence.getFrom().getStripped() self.connection.getRoster().Authorize(jabber_id) bot = Bot(**options) bot.loop() If I am not registering a precence handler, my message handler is always get invoked. But If I enable both presence and message handlers, message handler is not at all getting invoked. This problem was not there when the number of users were less. Is there anyway I can improve the performance by some way of threading? or any other ways so that both handlers get invoked without missing any messages? Thanks in advance Santhosh |