From 1366f7d3ca9bec3939474fc4774f83c681fc434f Mon Sep 17 00:00:00 2001 From: Jxck-S Date: Wed, 13 Oct 2021 21:27:38 -0400 Subject: [PATCH] Fix for hanging requests, Remove PID File - Removed PID file generation, uneeded use matching process to plane-notify name - Add timeout to requests for ADSBX, previously hanging. - Fix exception for Discord --- __main__.py | 16 +--------------- defADSBX.py | 2 +- defDiscord.py | 2 +- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/__main__.py b/__main__.py index 7bf188a..232480a 100644 --- a/__main__.py +++ b/__main__.py @@ -6,16 +6,6 @@ import traceback if platform.system() == "Windows": from colorama import init init(convert=True) -elif platform.system() == "Linux": - pid_file_path = "/home/plane-notify/pid.pid" - def write_pid_file(filepath): - import os - pid = str(os.getpid()) - f = open(filepath, 'w') - f.write(pid) - f.close() - write_pid_file(pid_file_path) - print("Made PIDFile") from planeClass import Plane from datetime import datetime import pytz @@ -63,7 +53,6 @@ def service_exit(signum, frame): if main_config.getboolean('DISCORD', 'ENABLE'): from defDiscord import sendDis sendDis("Service Stop", main_config) - os.remove(pid_file_path) raise SystemExit("Service Stop") signal.signal(signal.SIGTERM, service_exit) if os.path.isfile("lookup_route.py"): @@ -223,7 +212,4 @@ except Exception as e: logging.error(str(traceback.format_exc())) from defDiscord import sendDis sendDis(str("Error Exiting: " + str(e) + "Failed on " + key), main_config, "crash_latest.log") - raise e -finally: - if platform.system() == "Linux": - os.remove(pid_file_path) \ No newline at end of file + raise e \ No newline at end of file diff --git a/defADSBX.py b/defADSBX.py index f2f1efd..763bf7f 100644 --- a/defADSBX.py +++ b/defADSBX.py @@ -12,7 +12,7 @@ api_version = main_config.get('ADSBX', 'API_VERSION') def pull(url, headers): try: - response = requests.get(url, headers = headers) + response = requests.get(url, headers = headers, timeout=30) print ("HTTP Status Code:", response.status_code) response.raise_for_status() except (requests.HTTPError, ConnectionError, requests.Timeout, urllib3.exceptions.ConnectionError) as error_message: diff --git a/defDiscord.py b/defDiscord.py index 3649237..eb6e71c 100644 --- a/defDiscord.py +++ b/defDiscord.py @@ -9,5 +9,5 @@ def sendDis(message, config, file_name = None, role_id = None): webhook.add_file(file=f.read(), filename=file_name) try: webhook.execute() - except requests.Exceptions: + except requests.exceptions.RequestException: pass \ No newline at end of file