mirror of
https://github.com/clearml/clearml
synced 2025-05-03 04:21:00 +00:00
Fix PY3.x fails calling SemLock._after_fork with forkserver context, forking while lock is acquired (https://github.com/allegroai/clearml-agent/issues/73)
This commit is contained in:
parent
e47f570ce5
commit
14108c4f23
@ -233,6 +233,18 @@ class RLock(Lock):
|
||||
|
||||
def acquire(self, timeout=None, check_interval=None, fail_when_locked=None):
|
||||
if self._lock:
|
||||
# cleanup bad python behaviour when forking while lock is acquired
|
||||
# see Issue https://github.com/allegroai/clearml-agent/issues/73
|
||||
# and https://bugs.python.org/issue6721
|
||||
if self._pid != os.getpid():
|
||||
# noinspection PyBroadException
|
||||
try:
|
||||
if self._lock._semlock._count(): # noqa
|
||||
# this should never happen unless python forgot calling _after_fork
|
||||
self._lock._semlock._after_fork() # noqa
|
||||
except BaseException:
|
||||
pass
|
||||
|
||||
if not self._lock.acquire(block=timeout != 0, timeout=timeout):
|
||||
# We got a timeout... reraising
|
||||
raise exceptions.LockException()
|
||||
|
Loading…
Reference in New Issue
Block a user