decorator

Possible to create a @synchronized decorator that's aware of a method's object?

﹥>﹥吖頭↗ 提交于 2020-11-26 19:35:01
问题 I'm trying to create a @synchronized wrapper that creates one Lock per object and makes method calls thread safe. I can only do this if I can access method.im_self of the method in the wrapped method. class B: def f(self): pass assert inspect.ismethod( B.f ) # OK assert inspect.ismethod( B().f ) # OK print B.f # <unbound method B.f> print B().f # <bound method B.f of <__main__.B instance at 0x7fa2055e67e8>> def synchronized(func): # func is not bound or unbound! print func # <function f at

Possible to create a @synchronized decorator that's aware of a method's object?

一世执手 提交于 2020-11-26 19:34:38
问题 I'm trying to create a @synchronized wrapper that creates one Lock per object and makes method calls thread safe. I can only do this if I can access method.im_self of the method in the wrapped method. class B: def f(self): pass assert inspect.ismethod( B.f ) # OK assert inspect.ismethod( B().f ) # OK print B.f # <unbound method B.f> print B().f # <bound method B.f of <__main__.B instance at 0x7fa2055e67e8>> def synchronized(func): # func is not bound or unbound! print func # <function f at

Possible to create a @synchronized decorator that's aware of a method's object?

吃可爱长大的小学妹 提交于 2020-11-26 19:34:27
问题 I'm trying to create a @synchronized wrapper that creates one Lock per object and makes method calls thread safe. I can only do this if I can access method.im_self of the method in the wrapped method. class B: def f(self): pass assert inspect.ismethod( B.f ) # OK assert inspect.ismethod( B().f ) # OK print B.f # <unbound method B.f> print B().f # <bound method B.f of <__main__.B instance at 0x7fa2055e67e8>> def synchronized(func): # func is not bound or unbound! print func # <function f at