Skip to content

Commit 20124c4

Browse files
Aapo Kyrolafacebook-github-bot
authored andcommitted
guard dyndep with a lock (#26153)
Summary: Pull Request resolved: #26153 I am suspecting that our multithreaded test-system causes issue with dyndep, if two places try to concurrently InitOpsLibrary. So perhaps we just guard this by a lock. This is just a guess-fix, as it is impossible to repro. Test Plan: sandcastle Reviewed By: bddppq Differential Revision: D17361310 fbshipit-source-id: 596634a2098b18881abbd26a5a727a5ba0d03b6e
1 parent e293c4e commit 20124c4

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

caffe2/python/dyndep.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import ctypes
99
import os
10-
10+
from threading import Lock
1111
from caffe2.python import core, extension_loader
1212

1313

@@ -36,15 +36,17 @@ def InitOpsLibrary(name):
3636

3737

3838
_IMPORTED_DYNDEPS = set()
39+
dll_lock = Lock()
3940

4041

4142
def GetImportedOpsLibraries():
4243
return _IMPORTED_DYNDEPS
4344

4445

4546
def _init_impl(path):
46-
_IMPORTED_DYNDEPS.add(path)
47-
with extension_loader.DlopenGuard():
48-
ctypes.CDLL(path)
49-
# reinitialize available ops
50-
core.RefreshRegisteredOperators()
47+
with dll_lock:
48+
_IMPORTED_DYNDEPS.add(path)
49+
with extension_loader.DlopenGuard():
50+
ctypes.CDLL(path)
51+
# reinitialize available ops
52+
core.RefreshRegisteredOperators()

0 commit comments

Comments
 (0)