From d5f24888c207907bb79364d52665532fd13fe4ae Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 4 Mar 2021 11:41:51 -0600 Subject: [PATCH] Make lock files inheritable on Python >= 3.4 --- sched/start | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sched/start b/sched/start index 796b86611c..0ab6c00ab3 100755 --- a/sched/start +++ b/sched/start @@ -314,6 +314,12 @@ def lock_file(filename): file = open(filename,'w') locks.append(file) try: + # https://docs.python.org/3/library/os.html#inheritance-of-file-descriptors + # "Since Python 3.4, file descriptors created by Python are non-inheritable + # by default." Therefore, we must explicitly flag the file as inheritable, + # otherwise it will get discarded upon calling os.execvp() and the lock + # will be lost. + "set_inheritable" in dir(os) and os.set_inheritable(file.fileno(), True) return fcntl.lockf(file.fileno(), fcntl.LOCK_EX|fcntl.LOCK_NB) except IOError: return -1