mirror of https://github.com/BOINC/boinc.git
Make lock files inheritable on Python >= 3.4
This commit is contained in:
parent
8b151dbb98
commit
d5f24888c2
|
@ -314,6 +314,12 @@ def lock_file(filename):
|
||||||
file = open(filename,'w')
|
file = open(filename,'w')
|
||||||
locks.append(file)
|
locks.append(file)
|
||||||
try:
|
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)
|
return fcntl.lockf(file.fileno(), fcntl.LOCK_EX|fcntl.LOCK_NB)
|
||||||
except IOError:
|
except IOError:
|
||||||
return -1
|
return -1
|
||||||
|
|
Loading…
Reference in New Issue