Question about expression evaluation

Peter Otten __peter__ at web.de
Mon Nov 8 13:06:18 EST 2010


Scott Gould wrote:

> Thanks for the ideas, everyone. It's probably obvious that this is in
> a Django context, and while I do have WSGI configured to multi-thread
> its processes, there is nothing explicitly shared -- via threading, a
> multi-user situation, or otherwise -- about this data. It is entirely
> local to the request so I can't figure out how the "contact" object
> could change in a single line of code.
> 
> But obviously there must be something going on like what you all
> suggest. I just can't figure out how. This is the entirety of the
> contact-producing code within Account:
> 
>         @property
>         def contact(self):
>                 if not hasattr(self, '_contact'):

If one thread stops this point the _contact attribute is not yet set and 
another thread may trigger the if-suite, too.

>                         self._contact = 
get_contact_for_id(self.profile.id) if self.profile
> and self.profile.id else None
>                 return self._contact
> 
> As you can see, it's essentially read-only so once a self._contact
> always a self._contact. (Unless I'm misunderstanding something
> fundamental, which as an admitted amateur I could well be!)




More information about the Python-list mailing list