mirror of
https://github.com/open-mmlab/mmcv.git
synced 2025-06-03 21:54:52 +08:00
[Fix] Fix data race risk of cache_randomness
(#2927)
This commit is contained in:
parent
c0268ad974
commit
4f65f91db6
@ -1,5 +1,6 @@
|
||||
# Copyright (c) OpenMMLab. All rights reserved.
|
||||
|
||||
import copy
|
||||
import functools
|
||||
import inspect
|
||||
import weakref
|
||||
@ -80,7 +81,10 @@ class cache_randomness:
|
||||
|
||||
def __get__(self, obj, cls):
|
||||
self.instance_ref = weakref.ref(obj)
|
||||
return self
|
||||
# Return a copy to avoid multiple transform instances sharing
|
||||
# one `cache_randomness` instance, which may cause data races
|
||||
# in multithreading cases.
|
||||
return copy.copy(self)
|
||||
|
||||
|
||||
def avoid_cache_randomness(cls):
|
||||
|
Loading…
x
Reference in New Issue
Block a user