RfD: Automagically making a class instance 'synchronized' (draft impl.)
pyth at devel.trillke.net
Tue Jun 11 18:04:25 EDT 2002
Gerhard H?ring wrote:
> For one of my projects, I'll need something not quite unlike the
> following code. It's not tested, yet, but it looks ok and complete to
> me. I thought that it could be useful to other developers who need to
> use multithreading, so I'm posting it here. Maybe something like this
> would even be a useful addition to the Standard Library?
note that Ian Kjos some weeks ago send a nice module 'morethreading.py'
to the dev-list. IIRC, it still waits for beeing reviewed and extended
with other ideas (like synchronized methods).
> from threading import RLock
> def __call__(self, *args, **kwargs):
I think for inclusion into the standard lib it *might* be
worth to reduce overhead (doubly-indirect function calls + lookups).
A quick google search showed there has already been some discussion
on this issue and there seems to be a 'synchronizing' metaclass.
anyway, another comment:
> self.obj(*args, **kwargs)
this can be safely substituted and then even returns the correct value<wink> with
return self.obj(*args, **kwargs)
the finally statement is executed in all cases and doesn't hinder
an exception to be raised eventually. I think it was designed
for use cases exactly like this :-)
More information about the Python-list