[issue15634] synchronized decorator for the threading module

2012-08-14 Thread Juan Javier
Juan Javier added the comment: Ok, you are right, serialized is the right name. Also, passing the lock to the decorator will the correct option. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15634

[issue15634] synchronized decorator for the threading module

2012-08-14 Thread Juan Javier
Juan Javier added the comment: What about this? def serialized(lock): def _serialized(func): def __serialized(*args, **kwds): with lock: return func(*args, **kwds) __serialized.__doc__ = func.__doc__ return __serialized return

[issue15634] synchronized decorator for the threading module

2012-08-13 Thread Juan Javier
New submission from Juan Javier: I think it will be useful to have a decorator like this one on the threading module: def synchronized(func): A decorator to make a function execution synchronized. Examples: @synchronized def foo(): pass class Foo: def

[issue15634] synchronized decorator for the threading module

2012-08-13 Thread R. David Murray
R. David Murray added the comment: Writing such a decorator is pretty trivial to do. On the other hand, I've done it often enough that I could be convinced it is useful to add. I think it would be better to have a decorator generator that takes a lock as its argument, however, since an

[issue15634] synchronized decorator for the threading module

2012-08-13 Thread R. David Murray
R. David Murray added the comment: Oh, I misread your code. The code I'm working on uses the lock to serialize several different functions, and your decorator wouldn't work for that. -- ___ Python tracker rep...@bugs.python.org

[issue15634] synchronized decorator for the threading module

2012-08-13 Thread Antoine Pitrou
Antoine Pitrou added the comment: I'm not sure how useful that is in practice. Often you want to use the same lock accross several functions or methods. Also, I think it would be more accurate to call this serialized than synchronized. -- nosy: +jyasskin, pitrou