Browse Source

Fix some Python 3.8 related issues

tags/nilmdb-2.0.2^0
Jim Paris 9 months ago
parent
commit
a41111b045
2 changed files with 17 additions and 1 deletions
  1. +14
    -0
      nilmdb/server/serverutil.py
  2. +3
    -1
      nilmdb/utils/timestamper.py

+ 14
- 0
nilmdb/server/serverutil.py 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):


+ 3
- 1
nilmdb/utils/timestamper.py 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:


Loading…
Cancel
Save