comparison eprodbus.py @ 21:625064987b7c

Wrap gobject callbacks in exit_on_error to make more robust
author Daniel O'Connor <darius@dons.net.au>
date Thu, 09 Dec 2021 23:52:54 +1030
parents 8d48ca5294d3
children 02ba26698696
comparison
equal deleted inserted replaced
20:8d48ca5294d3 21:625064987b7c
14 import sqlite3 14 import sqlite3
15 import sys 15 import sys
16 16
17 sys.path.insert(1, os.path.join(os.path.dirname(__file__), 'velib_python')) 17 sys.path.insert(1, os.path.join(os.path.dirname(__file__), 'velib_python'))
18 from vedbus import VeDbusService 18 from vedbus import VeDbusService
19 from ve_utils import exit_on_error
19 20
20 logger = logging.getLogger('eprodbus') 21 logger = logging.getLogger('eprodbus')
21 logger.setLevel(logging.INFO) 22 logger.setLevel(logging.INFO)
22 23
23 formatter = logging.Formatter('%(asctime)s - %(message)s') 24 formatter = logging.Formatter('%(asctime)s - %(message)s')
45 self.log_queue = [] 46 self.log_queue = []
46 self.dbusservice = dbusservice 47 self.dbusservice = dbusservice
47 self.p = epro.Processor() 48 self.p = epro.Processor()
48 self.s = s 49 self.s = s
49 self.dbh = dbh 50 self.dbh = dbh
50 gobject.io_add_watch(s.fileno(), gobject.IO_IN, self.read_serial) 51 gobject.io_add_watch(s.fileno(), gobject.IO_IN, lambda fd, userdata: exit_on_error(self.read_serial, fd, userdata))
51 gobject.timeout_add(60000, self.log_epro) 52 gobject.timeout_add(60000, exit_on_error, self.log_epro)
52 53
53 def read_serial(self, fd, userdata): 54 def read_serial(self, fd, userdata):
54 try: 55 try:
55 data = self.s.read(1024) 56 data = self.s.read(1024)
56 except Exception as e: 57 except Exception as e: