Stop regexp processing after timeput (60sec)

Minor pep8 fixes
pull/266/head
kovacsbalu 2018-10-08 11:25:32 +02:00
parent a414a84044
commit 6d199f0150
1 changed files with 36 additions and 16 deletions

View File

@ -9,20 +9,29 @@ supplied in the term webpage.
import redis
import time
from pubsublogger import publisher
from packages import lib_words
from packages import Paste
import os
from os import environ
import datetime
import calendar
import re
import signal
import time
from Helper import Process
# Email notifications
from NotificationHelper import *
class TimeoutException(Exception):
pass
def timeout_handler(signum, frame):
raise TimeoutException
signal.signal(signal.SIGALRM, timeout_handler)
# Config Variables
DICO_REFRESH_TIME = 60 # s
PROCESS_TIMEOUT = 60
BlackListTermsSet_Name = "BlackListSetTermSet"
TrackedTermsSet_Name = "TrackedSetTermSet"
@ -38,6 +47,7 @@ top_termFreq_set_array = [top_termFreq_setName_day,top_termFreq_setName_week, to
# create direct link in mail
full_paste_url = "/showsavedpaste/?paste="
def refresh_dicos():
dico_regex = {}
dico_regexname_to_redis = {}
@ -91,7 +101,17 @@ if __name__ == "__main__":
# iterate the word with the regex
for regex_str, compiled_regex in dico_regex.items():
signal.alarm(PROCESS_TIMEOUT)
try:
matched = compiled_regex.search(content)
except TimeoutException:
log_msg = "{0} processing timeout".format(filename)
print (log_msg)
publisher.critical(log_msg)
continue
else:
signal.alarm(0)
if matched is not None: # there is a match
print('regex matched {}'.format(regex_str))