Mercurial > libervia-web
comparison libervia/web/server/server.py @ 1594:93abef9a3548
server: catch `DBusException` and retry to connect in this case.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 13 Dec 2023 22:03:49 +0100 |
parents | 291a7026cb2b |
children | 86c7a3a625d5 |
comparison
equal
deleted
inserted
replaced
1593:c6976c5b85a1 | 1594:93abef9a3548 |
---|---|
25 from typing import Callable, Dict, Optional | 25 from typing import Callable, Dict, Optional |
26 import urllib.error | 26 import urllib.error |
27 import urllib.parse | 27 import urllib.parse |
28 import urllib.request | 28 import urllib.request |
29 | 29 |
30 from dbus.exceptions import DBusException | |
30 from twisted.application import service | 31 from twisted.application import service |
31 from twisted.internet import defer, inotify, reactor | 32 from twisted.internet import defer, inotify, reactor |
32 from twisted.python import failure | 33 from twisted.python import failure |
33 from twisted.python import filepath | 34 from twisted.python import filepath |
34 from twisted.python.components import registerAdapter | 35 from twisted.python.components import registerAdapter |
646 lambda failure: self.initialised.errback(Exception(failure)), | 647 lambda failure: self.initialised.errback(Exception(failure)), |
647 ) | 648 ) |
648 self.initialised.addCallback(lambda __: defer.ensureDeferred(self.backend_ready())) | 649 self.initialised.addCallback(lambda __: defer.ensureDeferred(self.backend_ready())) |
649 | 650 |
650 def _bridge_eb(self, failure_): | 651 def _bridge_eb(self, failure_): |
651 if isinstance(failure_, BridgeExceptionNoService): | 652 if ( |
653 isinstance(failure_, BridgeExceptionNoService) | |
654 or isinstance(failure_, DBusException) | |
655 ): | |
652 if self._bridge_retry: | 656 if self._bridge_retry: |
653 if self._bridge_retry < 0: | 657 if self._bridge_retry < 0: |
654 print(_("Can't connect to bridge, will retry indefinitely. " | 658 print(_("Can't connect to bridge, will retry indefinitely. " |
655 "Next try in 1s.")) | 659 "Next try in 1s.")) |
656 else: | 660 else: |
663 ) | 667 ) |
664 time.sleep(1) | 668 time.sleep(1) |
665 self.bridge.bridge_connect(callback=self._bridge_cb, errback=self._bridge_eb) | 669 self.bridge.bridge_connect(callback=self._bridge_cb, errback=self._bridge_eb) |
666 return | 670 return |
667 | 671 |
668 print("Can't connect to SàT backend, are you sure it's launched ?") | 672 print("Can't connect to Libervia backend, are you sure it's launched?") |
669 else: | 673 else: |
670 log.error("Can't connect to bridge: {}".format(failure)) | 674 log.exception("Can't connect to bridge") |
671 sys.exit(1) | 675 sys.exit(1) |
672 | 676 |
673 @property | 677 @property |
674 def version(self): | 678 def version(self): |
675 """Return the short version of Libervia""" | 679 """Return the short version of Libervia""" |