From 0640c904893735d99c21065bbc1380abaf5ad1d7 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Wed, 16 Feb 2022 12:43:22 +0100 Subject: [PATCH] =?UTF-8?q?Meilleur=20red=C3=A9marrage=20apr=C3=A8s=20erre?= =?UTF-8?q?ur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/main.py b/main.py index 119ff54..5f9bd9c 100755 --- a/main.py +++ b/main.py @@ -84,22 +84,27 @@ if __name__ == '__main__': if not nick: nick = "Isengard" - xmpp = MUCBot(jid, password, rooms.split(","), nick) - xmpp.register_plugin('xep_0030') # Service Discovery - xmpp.register_plugin('xep_0045') # Multi-User Chat - xmpp.register_plugin('xep_0199') # XMPP Ping - - # Create buffer - store = DataStore(xmpp) - xmpp.datastore = store - - localservthread = LocalServer(store) - localservthread.start() - ERRORS = 0 + store = None + localservthread = None while True: - time.sleep(1) + + xmpp = MUCBot(jid, password, rooms.split(","), nick) + xmpp.register_plugin('xep_0030') # Service Discovery + xmpp.register_plugin('xep_0045') # Multi-User Chat + xmpp.register_plugin('xep_0199') # XMPP Ping + + # Create buffer + if not store: + store = DataStore(xmpp) + xmpp.datastore = store + + # Launch local server + if not localservthread: + localservthread = LocalServer(store) + localservthread.start() + time.sleep(1) # Connect to the XMPP server and start processing XMPP stanzas. xmpp.connect() @@ -113,9 +118,10 @@ if __name__ == '__main__': except KeyboardInterrupt: cleanExit() except Exception as e: - log.error(str(e)) + log.error("ERROR IN MAIN : " + str(e)) if ERRORS >= 3: log.critical("3 consecutive errors. Aborting...") cleanExit() ERRORS += 1 + del xmpp