Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit af2b2e4

Browse files
committed
fix synchronized methods to lock per-instance not per-method
1 parent 3f2407d commit af2b2e4

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

java2python/mod/include/sync.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
from threading import RLock
22

3-
_locks = {}
4-
def lock_for_object(obj, locks=_locks):
3+
def lock_for_object(obj, locks={}):
54
return locks.setdefault(id(obj), RLock())
65

7-
86
def synchronized(call):
7+
assert call.__code__.co_varnames[0] in {'self', 'cls'}
98
def inner(*args, **kwds):
10-
with lock_for_object(call):
9+
with lock_for_object(args[0]):
1110
return call(*args, **kwds)
1211
return inner

0 commit comments

Comments
 (0)