remove multiprocessing

This commit is contained in:
petrucci4prez 2017-05-29 18:04:50 -04:00
parent b36536b48b
commit 5d7505d63a
2 changed files with 4 additions and 40 deletions

27
main.py
View File

@ -2,8 +2,6 @@
import os, time, signal, traceback
import RPi.GPIO as GPIO
from queue import Queue
from multiprocessing.managers import BaseManager
from auxilary import fallbackLogger
@ -18,7 +16,6 @@ def clean():
except NameError:
pass
# TODO: this part is really wordy and makes me sad
try:
logger.info('Terminated root process - PID: %s', os.getpid())
logger.stop()
@ -27,26 +24,10 @@ def clean():
except Exception:
printTrace(traceback.format_exc())
try:
manager.__del__() # kill process 2
except NameError:
pass
except Exception:
printTrace(traceback.format_exc())
def sigtermHandler(signum, stackFrame):
logger.info('Caught SIGTERM')
raise SystemExit
class ResourceManager(BaseManager):
def __init__(self):
super().__init__()
self.register('Queue', Queue)
def __del__(self):
self.shutdown()
if __name__ == '__main__':
try:
os.chdir(os.path.dirname(os.path.realpath(__file__)))
@ -54,14 +35,8 @@ if __name__ == '__main__':
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
manager = ResourceManager()
manager.start() # Child process 1
loggerQueue = manager.Queue() # used to buffer logs
ttsQueue = manager.Queue() # used as buffer for TTS Engine
from sharedLogging import MasterLogger
logger = MasterLogger(__name__, 'DEBUG', loggerQueue)
logger = MasterLogger(__name__, 'DEBUG')
from notifier import criticalError

View File

@ -1,16 +1,9 @@
import logging, os
from subprocess import run, PIPE, CalledProcessError
from logging.handlers import TimedRotatingFileHandler, QueueListener, QueueHandler
from logging.handlers import TimedRotatingFileHandler
from auxilary import fallbackLogger
def SlaveLogger(name, level, queue):
logger = logging.getLogger(name)
logger.setLevel(getattr(logging, level))
logger.addHandler(QueueHandler(queue))
logger.propagate = False
return logger
class GlusterFS():
def __init__(self, server, volume, mountpoint, options=None):
if not os.path.exists(mountpoint):
@ -46,7 +39,7 @@ class GlusterFS():
raise SystemExit
class MasterLogger():
def __init__(self, name, level, queue):
def __init__(self, name, level):
mountpoint = '/mnt/glusterfs/pyledriver'
self.fs = GlusterFS('192.168.11.39', 'pyledriver', mountpoint, 'backupvolfile-server=192.168.11.48')
@ -70,7 +63,7 @@ class MasterLogger():
self.rotatingFile = TimedRotatingFileHandler(logdest + '/pyledriver-log', when='midnight')
self.rotatingFile.setFormatter(fileFormat)
logging.basicConfig(level=getattr(logging, level), handlers=[QueueHandler(queue)])
logging.basicConfig(level=getattr(logging, level), handlers=[console, self.rotatingFile])
logger = logging.getLogger(name)
# since the logger module sucks and doesn't allow me to init
@ -78,10 +71,6 @@ class MasterLogger():
for i in ['debug', 'info', 'warning', 'error', 'critical']:
setattr(self, i, getattr(logger, i))
self.queListener = QueueListener(queue, console, self.rotatingFile)
self.queListener.start()
def stop(self):
self.queListener.stop()
self.rotatingFile.close() # must close file stream before unmounting
self.fs.unmount()