@@ -567,7 +567,13 @@ def _serialize(data):
567
567
return np .frombuffer (buffer , dtype = np .uint8 )
568
568
569
569
570
- _active_tensor_caches : MutableMapping [str , "TensorCache" ] = weakref .WeakValueDictionary ()
570
+ _active_tensor_caches : MutableMapping [int , "TensorCache" ] = weakref .WeakValueDictionary ()
571
+
572
+
573
+ def _unique_file_id (path : Union [str , PathLike ]) -> int :
574
+ result = os .stat (path ).st_ino
575
+ assert result != 0
576
+ return result
571
577
572
578
573
579
class TensorCache (MutableMapping [str , Tensor ], ABC ):
@@ -584,7 +590,10 @@ def __new__(cls, filename: Union[str, PathLike], *, read_only: bool = False, **k
584
590
# This mechanism makes sure we re-use open lmdb file handles. Lmdb has a problem when the same file is
585
591
# opened by the same process multiple times. This is our workaround.
586
592
filename = str (filename )
587
- result = _active_tensor_caches .get (filename )
593
+ try :
594
+ result = _active_tensor_caches .get (_unique_file_id (filename ))
595
+ except FileNotFoundError :
596
+ result = None
588
597
if result is None :
589
598
result = super (TensorCache , cls ).__new__ (
590
599
cls , filename , read_only = read_only , ** kwargs
@@ -691,7 +700,7 @@ def __init__(
691
700
readonly = read_only ,
692
701
lock = use_lock ,
693
702
)
694
- _active_tensor_caches [self . lmdb_env . path ( )] = self
703
+ _active_tensor_caches [_unique_file_id ( filename )] = self
695
704
696
705
# We have another cache here that makes sure we return the same object for the same key. Without it,
697
706
# you would get a different tensor, using different memory, every time you call __getitem__(), even
0 commit comments