Compare commits

...

2 Commits

Author SHA1 Message Date
a41111b045 Fix some Python 3.8 related issues 2020-08-03 17:48:51 -04:00
85f822e1c4 Decode non-JSON HTTP responses when possible
This doesn't affect anything in nilmdb, but is needed by nilmrun.
2020-08-03 17:31:11 -04:00
3 changed files with 18 additions and 2 deletions

View File

@@ -109,7 +109,7 @@ class HTTPClient():
stream=False, headers=headers)
if isjson:
return json.loads(response.content)
return response.content
return response.text
def get(self, url, params=None):
"""Simple GET (parameters in URL)"""

View File

@@ -6,6 +6,7 @@ import sys
import json
import decorator
import functools
import threading
import cherrypy
@@ -178,6 +179,19 @@ def cherrypy_patch_exit():
os._exit = real_exit
bus.exit = functools.partial(patched_exit, bus.exit)
# A behavior change in Python 3.8 means that some thread exceptions,
# derived from SystemExit, now print tracebacks where they didn't
# used to: https://bugs.python.org/issue1230540
# Install a thread exception hook that ignores CherryPyExit;
# to make this match the behavior where we didn't set
# threading.excepthook, we also need to ignore SystemExit.
def hook(args):
if args.exc_type == CherryPyExit or args.exc_type == SystemExit:
return
sys.excepthook(args.exc_type, args.exc_value,
args.exc_traceback) # pragma: no cover
threading.excepthook = hook
# Start/stop CherryPy standalone server
def cherrypy_start(blocking=False, event=False):

View File

@@ -26,7 +26,9 @@ class Timestamper():
return b""
if line[0:1] == b'#':
continue
break
# For some reason, coverage on python 3.8 reports that
# we never hit this break, even though we definitely do.
break # pragma: no cover
try:
return next(self.ts_iter) + line
except StopIteration: