From: Евгений Ч. <nec...@gm...> - 2010-05-20 12:11:51
|
Sorry for my bad English - Google Translate Hello, I'm writing a program with a graphical interface for PyQt That's decided to add the ability to send logs and receive commands remotely with Xmpp That is a normal working code to work with xmpp class JabberBot(): def __init__(self): self.password='blablalba' # pass self.jid self.jid='BLA...@gm...' #send jid self.jid2='bla...@gm...' #take jid self.jid3='bla...@gm...' #manager commands jid jid=xmpp.protocol.JID(self.jid) self.server = jid.getDomain() self.user = jid.getNode() def connect_jid(self): self.conn = xmpp.Client(self.server, debug = []) if (self.server=='gmail.com'): print ('connect to google ', self.server) conres = self.conn.connect(('talk.google.com',5223)) else: conres = self.conn.connect() if not conres: print "Unable to connect to server %s!" % self.server sys.exit(1) if conres == 'tls': print "We have TLS connection!" elif conres == 'ssl': print "We have SSL connection!" else: print "Warning: unable to estabilish secure connection - TLS & SSL failed!" authres = self.conn.auth(self.user, self.password) if not authres: print "Unable to authorize on %s - check login/password." % self.server sys.exit(1) if authres <> 'sasl': print """Warning: unable to perform SASL auth os %s. Old authentication method used!""" % self.server #set status presence = xmpp.Presence(status = "Ready!", show ="chat", priority = '1') self.conn.send(presence) #return myclient def send(self,text): print text mymsg=xmpp.protocol.Message(self.jid2,text, "chat") self.conn.send(mymsg) print mymsg def message_handler(self, conn, message): print "new message!" if (re.findall(r'^('+self.jid3+r')/', str(message.getFrom()))): command=str(message.getBody()) print "from: " + str(message.getFrom()) print "msg: " + str(message.getBody()) if (command=='exit'): print 'exit' try: self.conn.disconnected() except: print 'errrrrr' self.exit=1 else: print 'msg not in trust' def run(self): self.connect_jid() self.conn.RegisterHandler('message', self.message_handler) while self.step_on(): pass def step_on(self): if (self.exit==1): return 0 try: self.conn.Process(1) print 1 except KeyboardInterrupt: return 0 return 1 bot = JabberBot() bot.run() This code works fine if you send the command 'exit' it will be run code: if (command=='exit'): print 'exit' try: self.conn.disconnected() except: print 'errrrrr' self.exit=1 In principle, sufficiently pure self.exit and then everything will come, self.conn.disconnected () here because for redundancy. But as soon as I stuffed it all in QtCore.QThread - make class JabberBot (QtCore.QThread) Start: self.jb = JabberBot(self) self.jb.start() Actually everything is working the team accepted the message sent. But the problem is that when I send the 'exit' command - session is not closed. User stays in the network. But apparently that "def step_on (self)" cease to do "print 1", and even if I do: if self.jb.isRunning(): print 'qqqq' else: print 'zzzz' It gives 'zzzz', which indicates the completion of this work Thread. But user stay online =( And no longer takes command But as soon as I complete the program my JabberBot immediately disappears from the list. How to make that all actually happened 100% off the user? |