Skip to content

Commit

Permalink
Remove bogus exception handling and improve loop stability. #57
Browse files Browse the repository at this point in the history
  • Loading branch information
infothrill committed Jan 12, 2018
1 parent 877308a commit 5d89b60
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Expand Up @@ -8,6 +8,7 @@ Release history
- switched to `pytest <https://pytest.org>`_ for running tests
- changed (**INCOMPATIBLE**): dropped support for python 2.6 and python 3.3
- added: new command line option -v to control verbosity
- improved: infinite loop and daemon stability, diagnostics #57
- improved: updated list of external urls for IP discovery
- improved: install documentation updated
- improved: add many missing docstrings and fixed many code smells
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -3,7 +3,7 @@
PYTHON=python3

publish:
echo "Use 'python setup.py sdist bdist_wheel; twine'"
@echo "Use 'python setup.py sdist bdist_wheel; twine'"

deb:
# this requires `apt-get install debhelper python3-all`
Expand Down
19 changes: 14 additions & 5 deletions dyndnsc/cli.py
Expand Up @@ -17,6 +17,9 @@
from .common.dynamiccli import parse_cmdline_args


LOG = logging.getLogger(__name__)


def list_presets(cfg, out=sys.stdout):
"""Write a human readable list of available presets to out.
Expand Down Expand Up @@ -81,11 +84,17 @@ def run_forever(dyndnsclients):
:param dyndnsclients: list of DynDnsClients
"""
while True:
# Do small sleeps in the main loop, needs_check() is cheap and does
# the rest.
time.sleep(15)
for dyndnsclient in dyndnsclients:
dyndnsclient.check()
try:
# Do small sleeps in the main loop, needs_check() is cheap and does
# the rest.
time.sleep(15)
for dyndnsclient in dyndnsclients:
dyndnsclient.check()
except (KeyboardInterrupt,):
break
except (Exception,) as exc:
LOG.critical("An exception occurred in the dyndns loop", exc_info=exc)
return 0


def main():
Expand Down
11 changes: 2 additions & 9 deletions dyndnsc/updater/duckdns.py
Expand Up @@ -56,15 +56,8 @@ def update(self, ip):
else:
params["ip"] = ip
# LOG.debug("Update params: %r", params)
try:
req = requests.get(self.url(), params=params, headers=constants.REQUEST_HEADERS_DEFAULT,
timeout=timeout)
except (requests.exceptions.Timeout, requests.exceptions.ConnectionError) as exc:
LOG.warning("an error occurred while updating IP at '%s'",
self.url(), exc_info=exc)
return False
else:
req.close()
req = requests.get(self.url(), params=params, headers=constants.REQUEST_HEADERS_DEFAULT,
timeout=timeout)
LOG.debug("status %i, %s", req.status_code, req.text)
# TODO: duckdns response codes seem undocumented...
if req.status_code == 200:
Expand Down
11 changes: 2 additions & 9 deletions dyndnsc/updater/dyndns2.py
Expand Up @@ -41,15 +41,8 @@ def update(self, ip):
timeout = 60
LOG.debug("Updating '%s' to '%s' at service '%s'", self.hostname, ip, self.url())
params = {"myip": ip, "hostname": self.hostname}
try:
req = requests.get(self.update_url(), params=params, headers=constants.REQUEST_HEADERS_DEFAULT,
auth=(self.userid, self.password), timeout=timeout)
except (requests.exceptions.Timeout, requests.exceptions.ConnectionError) as exc:
LOG.warning("an error occurred while updating IP at '%s'",
self.update_url(), exc_info=exc)
return False
else:
req.close()
req = requests.get(self.update_url(), params=params, headers=constants.REQUEST_HEADERS_DEFAULT,
auth=(self.userid, self.password), timeout=timeout)
LOG.debug("status %i, %s", req.status_code, req.text)
if req.status_code == 200:
# responses can also be "nohost", "abuse", "911", "notfqdn"
Expand Down

0 comments on commit 5d89b60

Please sign in to comment.