Add global exception handler to make sure everything goes to the log and not stderr.
This commit is contained in:
parent
b1822af576
commit
f4151e2071
|
@ -37,6 +37,7 @@ from hashlib import sha256
|
||||||
from time import time
|
from time import time
|
||||||
from bitstring import BitArray
|
from bitstring import BitArray
|
||||||
import socket
|
import socket
|
||||||
|
import sys
|
||||||
|
|
||||||
# Twisted is pretty important, so I keep it separate
|
# Twisted is pretty important, so I keep it separate
|
||||||
from twisted.internet.protocol import DatagramProtocol
|
from twisted.internet.protocol import DatagramProtocol
|
||||||
|
@ -115,6 +116,7 @@ class HBSYSTEM(DatagramProtocol):
|
||||||
self._system = _name
|
self._system = _name
|
||||||
self._logger = _logger
|
self._logger = _logger
|
||||||
self._config = self._CONFIG['SYSTEMS'][self._system]
|
self._config = self._CONFIG['SYSTEMS'][self._system]
|
||||||
|
sys.excepthook = self.handle_exception
|
||||||
|
|
||||||
# Define shortcuts and generic function names based on the type of system we are
|
# Define shortcuts and generic function names based on the type of system we are
|
||||||
if self._config['MODE'] == 'MASTER':
|
if self._config['MODE'] == 'MASTER':
|
||||||
|
@ -135,6 +137,12 @@ class HBSYSTEM(DatagramProtocol):
|
||||||
if self._config['EXPORT_AMBE']:
|
if self._config['EXPORT_AMBE']:
|
||||||
self._ambe = AMBE()
|
self._ambe = AMBE()
|
||||||
|
|
||||||
|
def handle_exception(self, exc_type, exc_value, exc_traceback):
|
||||||
|
if issubclass(exc_type, KeyboardInterrupt):
|
||||||
|
sys.__excepthook__(exc_type, exc_value, exc_traceback)
|
||||||
|
return
|
||||||
|
self._logger.error("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))
|
||||||
|
|
||||||
def startProtocol(self):
|
def startProtocol(self):
|
||||||
# Set up periodic loop for tracking pings from clients. Run every 'PING_TIME' seconds
|
# Set up periodic loop for tracking pings from clients. Run every 'PING_TIME' seconds
|
||||||
self._system_maintenance = task.LoopingCall(self.maintenance_loop)
|
self._system_maintenance = task.LoopingCall(self.maintenance_loop)
|
||||||
|
|
Loading…
Reference in New Issue