Unverified Commit 4f65f91d authored by Haobo Yuan's avatar Haobo Yuan Committed by GitHub
Browse files

[Fix] Fix data race risk of `cache_randomness` (#2927)

parent c0268ad9
# Copyright (c) OpenMMLab. All rights reserved. # Copyright (c) OpenMMLab. All rights reserved.
import copy
import functools import functools
import inspect import inspect
import weakref import weakref
...@@ -80,7 +81,10 @@ class cache_randomness: ...@@ -80,7 +81,10 @@ class cache_randomness:
def __get__(self, obj, cls): def __get__(self, obj, cls):
self.instance_ref = weakref.ref(obj) 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): def avoid_cache_randomness(cls):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment