From 468715abb311f588461087dd8aa424f04100e429 Mon Sep 17 00:00:00 2001 From: Will McCutchen Date: Mon, 1 Feb 2021 09:38:23 -0500 Subject: [PATCH] adapters: safely parse DEBUG environment variable Parse the value of the DEBUG environment variable defensively, to guard against breaking processes where the inotify package is imported but the value of DEBUG is not guaranteed to be an integer (e.g. as part of `gunicorn --reload`). --- inotify/adapters.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/inotify/adapters.py b/inotify/adapters.py index e8301da..f1aeaff 100644 --- a/inotify/adapters.py +++ b/inotify/adapters.py @@ -34,7 +34,11 @@ ]) _STRUCT_HEADER_LENGTH = struct.calcsize(_HEADER_STRUCT_FORMAT) -_IS_DEBUG = bool(int(os.environ.get('DEBUG', '0'))) + +try: + _IS_DEBUG = bool(int(os.environ.get('DEBUG', '0'))) +except ValueError: + _IS_DEBUG = False class EventTimeoutException(Exception):