diff options
author | Armin Rigo <armin.rigo@gmail.com> | 2020-03-03 01:37:25 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-03 01:37:25 (GMT) |
commit | 6daa37fd42c5d5300172728e8b4de74fe0b319fc (patch) | |
tree | fea0f80ed7f996670197dc3b60896b306b29dc9b /Lib/importlib | |
parent | ce3a4984089b8e0ce5422ca32d75ad057b008074 (diff) | |
download | cpython-6daa37fd42c5d5300172728e8b4de74fe0b319fc.zip cpython-6daa37fd42c5d5300172728e8b4de74fe0b319fc.tar.gz cpython-6daa37fd42c5d5300172728e8b4de74fe0b319fc.tar.bz2 |
bpo-38091: Import deadlock detection causes deadlock (GH-17518)
Automerge-Triggered-By: @brettcannon
Diffstat (limited to 'Lib/importlib')
-rw-r--r-- | Lib/importlib/_bootstrap.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py index 7b74e88..e00b27e 100644 --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -67,6 +67,7 @@ class _ModuleLock: # Deadlock avoidance for concurrent circular imports. me = _thread.get_ident() tid = self.owner + seen = set() while True: lock = _blocking_on.get(tid) if lock is None: @@ -74,6 +75,14 @@ class _ModuleLock: tid = lock.owner if tid == me: return True + if tid in seen: + # bpo 38091: the chain of tid's we encounter here + # eventually leads to a fixpoint or a cycle, but + # does not reach 'me'. This means we would not + # actually deadlock. This can happen if other + # threads are at the beginning of acquire() below. + return False + seen.add(tid) def acquire(self): """ |