Skip to content

Commit 302a4fc

Browse files
committed
remove lock
1 parent bc5534c commit 302a4fc

File tree

1 file changed

+17
-21
lines changed
  • localstack-core/localstack/utils

1 file changed

+17
-21
lines changed

localstack-core/localstack/utils/patch.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import functools
22
import inspect
3-
import threading
43
import types
54
from typing import Any, Callable
65

@@ -73,7 +72,6 @@ def proxy(*args, **kwargs):
7372

7473
class Patch:
7574
applied_patches: list["Patch"] = []
76-
_lock: threading.RLock = threading.RLock()
7775
"""Bookkeeping for patches that are applied. You can use this to debug patches. For instance,
7876
you could write something like::
7977
@@ -99,27 +97,25 @@ def __init__(self, obj: Any, name: str, new: Any) -> None:
9997
self.is_applied = False
10098

10199
def apply(self):
102-
with self._lock:
103-
if self.is_applied:
104-
return
105-
106-
if self.old and self.name == "__getattr__":
107-
raise Exception("You can't patch class types implementing __getattr__")
108-
if not self.old and self.name != "__getattr__":
109-
raise AttributeError(f"`{self.obj.__name__}` object has no attribute `{self.name}`")
110-
setattr(self.obj, self.name, self.new)
111-
Patch.applied_patches.append(self)
112-
self.is_applied = True
100+
if self.is_applied:
101+
return
102+
103+
if self.old and self.name == "__getattr__":
104+
raise Exception("You can't patch class types implementing __getattr__")
105+
if not self.old and self.name != "__getattr__":
106+
raise AttributeError(f"`{self.obj.__name__}` object has no attribute `{self.name}`")
107+
setattr(self.obj, self.name, self.new)
108+
Patch.applied_patches.append(self)
109+
self.is_applied = True
113110

114111
def undo(self):
115-
with self._lock:
116-
if not self.is_applied:
117-
return
118-
119-
# If we added a method to a class type, we don't have a self.old. We just delete __getattr__
120-
setattr(self.obj, self.name, self.old) if self.old else delattr(self.obj, self.name)
121-
Patch.applied_patches.remove(self)
122-
self.is_applied = False
112+
if not self.is_applied:
113+
return
114+
115+
# If we added a method to a class type, we don't have a self.old. We just delete __getattr__
116+
setattr(self.obj, self.name, self.old) if self.old else delattr(self.obj, self.name)
117+
Patch.applied_patches.remove(self)
118+
self.is_applied = False
123119

124120
def __enter__(self):
125121
self.apply()

0 commit comments

Comments
 (0)