add possibility to start Plugins asynchron

If you are using many Plugins or Plugins with a long execution time you could execute them in an asynchronous manner.
It must be pointed out that enabling (0|1) this consume time, so don't use it for one rapid Plugin.
This commit is contained in:
JHCD 2015-07-30 18:55:36 +02:00
parent 3e7cc1f365
commit 30320b3c71
7 changed files with 59 additions and 8 deletions

View file

@ -402,6 +402,10 @@ finally:
finally: finally:
# Close Logging # Close Logging
logging.debug("close Logging") logging.debug("close Logging")
# Waiting for all Threads to write there logs
if globals.config.getboolean("BOSWatch","processAlarmAsync") == True:
logging.debug("waiting 3s for threads...")
time.sleep(3)
logging.info("BOSWatch exit()") logging.info("BOSWatch exit()")
logging.shutdown() logging.shutdown()
if nmaHandler: if nmaHandler:

View file

@ -23,6 +23,12 @@ backupCount = 7
#rtl_path = /usr/local/bin/ #rtl_path = /usr/local/bin/
#multimon_path = /usr/local/bin/ #multimon_path = /usr/local/bin/
# if you are using many Plugins or Plugins with a long execution time
# you could execute them in an asynchronous manner
# It must be pointed out that enabling (0|1) this consume time,
# so don't use it for one rapid Plugin
processAlarmAsync = 0
# Using RegEx-Filter (0|1) # Using RegEx-Filter (0|1)
# Filter-configuration in section [Filters] # Filter-configuration in section [Filters]
useRegExFilter = 0 useRegExFilter = 0

View file

@ -16,3 +16,8 @@ class MyTimedRotatingFileHandler(logging.handlers.TimedRotatingFileHandler):
def setBackupCount(self, backupCount): def setBackupCount(self, backupCount):
"""Set/Change backupCount""" """Set/Change backupCount"""
self.backupCount = backupCount self.backupCount = backupCount
def close(self):
"""Make shure logfile will be flushed"""
self.flush()
super(self.__class__, self).close()

View file

@ -11,14 +11,48 @@ Handler for the filter and plugins at an alarm
""" """
import logging # Global logger import logging # Global logger
from threading import Thread
from includes import globals # Global variables from includes import globals # Global variables
##
#
# decide to run AlarmHandler sync or async
#
def processAlarmHandler(typ, freq, data):
"""
Function to decide if the alarm process will call sync
@type typ: string (FMS|ZVEI|POC)
@param typ: Typ of the dataset
@type freq: string
@param freq: frequency of the SDR Stick
@type data: map of data (structure see interface.txt)
@param data: Contains the parameter
@requires: active plugins in pluginList
@requires: Configuration has to be set in the config.ini
@return: nothing
@exception: Exception if starting a Thread failed
"""
if globals.config.getboolean("BOSWatch","processAlarmAsync") == True:
logging.debug("starting processAlarm async")
try:
Thread(target=processAlarm, args=(typ, freq, data)).start()
except:
logging.error("Error in starting alarm processing async")
logging.debug("Error in starting alarm processing async", exc_info=True)
pass
else:
processAlarm(typ, freq, data)
## ##
# #
# main function for central filtering and calling the plugins # main function for central filtering and calling the plugins
# #
def processAlarm(typ,freq,data): def processAlarm(typ, freq, data):
""" """
Function to process filters and plugins at Alarm Function to process filters and plugins at Alarm
@ -59,4 +93,6 @@ def processAlarm(typ,freq,data):
pass pass
logging.debug("[END ALARM]") logging.debug("[END ALARM]")
except: except:
logging.exception("Error in alarm processing") logging.error("Error in alarm processing")
logging.debug("Error in alarm processing", exc_info=True)
pass

View file

@ -22,7 +22,7 @@ from includes import doubleFilter # double alarm filter
# #
def decode(freq, decoded): def decode(freq, decoded):
""" """
Export FMS Information from Multimon-NG RAW String and call alarmHandler.processAlarm() Export FMS Information from Multimon-NG RAW String and call alarmHandler.processAlarmHandler()
@type freq: string @type freq: string
@param freq: frequency of the SDR Stick @param freq: frequency of the SDR Stick
@ -59,7 +59,7 @@ def decode(freq, decoded):
# processing the alarm # processing the alarm
try: try:
from includes import alarmHandler from includes import alarmHandler
alarmHandler.processAlarm("FMS", freq, data) alarmHandler.processAlarmHandler("FMS", freq, data)
except: except:
logging.error("processing alarm failed") logging.error("processing alarm failed")
logging.debug("processing alarm failed", exc_info=True) logging.debug("processing alarm failed", exc_info=True)

View file

@ -61,7 +61,7 @@ def isAllowed(poc_id):
# #
def decode(freq, decoded): def decode(freq, decoded):
""" """
Export POCSAG Information from Multimon-NG RAW String and call alarmHandler.processAlarm() Export POCSAG Information from Multimon-NG RAW String and call alarmHandler.processAlarmHandler()
@type freq: string @type freq: string
@param freq: frequency of the SDR Stick @param freq: frequency of the SDR Stick
@ -117,7 +117,7 @@ def decode(freq, decoded):
# processing the alarm # processing the alarm
try: try:
from includes import alarmHandler from includes import alarmHandler
alarmHandler.processAlarm("POC", freq, data) alarmHandler.processAlarmHandler("POC", freq, data)
except: except:
logging.error("processing alarm failed") logging.error("processing alarm failed")
logging.debug("processing alarm failed", exc_info=True) logging.debug("processing alarm failed", exc_info=True)

View file

@ -44,7 +44,7 @@ def removeF(zvei):
# #
def decode(freq, decoded): def decode(freq, decoded):
""" """
Export ZVEI Information from Multimon-NG RAW String and call alarmHandler.processAlarm() Export ZVEI Information from Multimon-NG RAW String and call alarmHandler.processAlarmHandler()
@type freq: string @type freq: string
@param freq: frequency of the SDR Stick @param freq: frequency of the SDR Stick
@ -71,7 +71,7 @@ def decode(freq, decoded):
# processing the alarm # processing the alarm
try: try:
from includes import alarmHandler from includes import alarmHandler
alarmHandler.processAlarm("ZVEI", freq, data) alarmHandler.processAlarmHandler("ZVEI", freq, data)
except: except:
logging.error("processing alarm failed") logging.error("processing alarm failed")
logging.debug("processing alarm failed", exc_info=True) logging.debug("processing alarm failed", exc_info=True)