[Python-Dev] PEP 231, __findattr__()

Barry A. Warsaw barry@digicool.com
Mon, 4 Dec 2000 16:23:00 -0500

>>>>> "CT" == Christian Tismer <tismer@tismer.com> writes:

    CT> You want most probably do this: __findattr__ should not be
    CT> invoked again for this instance, with this attribute name, for
    CT> this "thread", until you are done.

First, I think the rule should be "__findattr__ should not be invoked
again for this instance, in this thread, until you are done".
I.e. once in __findattr__, you want all subsequent attribute
references to bypass findattr, because presumably, your instance now
has complete control for all accesses in this thread.  You don't want
to limit it to just the currently named attribute.

Second, if "this thread" is defined as _PyThreadState_Current, then we
have a simple solution, as I mapped out earlier.  We do a
PyThreadState_GetDict() and store the instance in that dict on entry
to __findattr__ and remove it on exit from __findattr__.  If the
instance can be found in the current thread's dict, we bypass

>>>>> "MZ" == Moshe Zadka <moshez@zadka.site.co.il> writes:

    MZ> I don't think this is a good idea -- continuations and
    MZ> coroutines might mess it up.

You might be right, but I'm not sure.

If we make __findattr__ thread safe according to the definition above,
and if uthread/coroutine/continuation safety can be accomplished by
the __findattr__ programmer's discipline, then I think that is enough.
IOW, if we can tell the __findattr__ author to not relinquish the
uthread explicitly during the __findattr__ call, we're cool.  Oh, and
as long as we're not somehow substantially reducing the utility of
__findattr__ by making that restriction.

What I worry about is re-entrancy that isn't under the programmer's
control, like the Real Thread-safety problem.