Late initialization using __getattribute__
bdesth.quelquechose at free.quelquepart.fr
Wed Sep 3 22:02:02 CEST 2008
bukzor a écrit :
> Thanks for the reply. Just to see it not work, I tried to remove
> __getattribute__ from LateInitMixIn, but couldn't get it to work.
??? Sorry, I don't get what you mean...
> My Base class is a C class (_mysql.connection from MySQLdb) that
> sometimes segfaults if you try to use it before it's fully
Then don't use it before it's fully initialized.
patient: "doctor, when I do this, it hurts"
doctor : "then don't do it"
More seriously, I have used MySQLdb for years on more than a dozen linux
distribs, and never had such a problem. Is this a known bug ? Or is
there something wrong with your setup ?
> so unfortunately I think I need to use __getattribute__
> to do this. I'm doing all this just to make the connection not
> actually connect until used.
I may be dumb, but I don't get how this is supposed to solve your
problem. But anyway : there's a known design pattern for what you're
trying to do, that doesn't require mixins nor messing with
__getattribute__ (which, I repeat, is more often than not something you
*don't* want to do). The name of the design pattern is "proxy". I
strongly suggest that you 1/ try to cure the real problem instead of
hacking around and 2/ read about the proxy design pattern.
My 2 cents...
More information about the Python-list