Meilleur redémarrage après erreur

This commit is contained in:
Adrien Bourmault 2022-02-16 12:43:22 +01:00
parent f71d5eec14
commit 0640c90489
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
1 changed files with 20 additions and 14 deletions

34
main.py
View File

@ -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