Skip to content

Commit

Permalink
[Fix] Fix data race risk of cache_randomness (#2927)
Browse files Browse the repository at this point in the history
  • Loading branch information
HarborYuan authored Sep 7, 2023
1 parent c0268ad commit 4f65f91
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion mmcv/transforms/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) OpenMMLab. All rights reserved.

import copy
import functools
import inspect
import weakref
Expand Down Expand Up @@ -80,7 +81,10 @@ def __call__(self, *args, **kwargs):

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):
Expand Down

0 comments on commit 4f65f91

Please sign in to comment.