Jan Martinek napsal(a): > Ahoj, > > poslal jsem to jako bugreport a zde je vyjádření vývojářů: > > https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1500167&group_id=5470 > > -------------- > On shutdown time, Python clears each module by replacing all > module entries with None. So at some point, it does > a1 = None # or a1 = None > and at some other point, it does > M = None > Depending on the order in which these happen, M might be > None (i.e. might not be class M anymore) when __del__ runs. > > The order in which these happen depends on the order which > the names have in the module's dict. This, in turn, > depends > on the hash values of the strings, modulo the size of the > dictionary. Apparently, "a1" gets hashed after > "M", but "a" > gets hashed before "M". > > This isn't really a bug, atleast not one that we plan to > fix. The order in which modules get emptied is unspecified, > and it can easily happen that things are gone when some > destructor runs. Classes should be written to be resistent > against this behaviour, e.g. by writing > > def __del__(self): > self.__class__.b = 0 # name "M" might be gone > already > > Closing this as "won't fix". > > ------------- > > Závěr je, že se nejedná o chybu, tedy alespoň ne takovou, kterou je v > plánu opravit. Doporučuje se používat self.__class__. > > Děkuji všem za reakce. Zůstává mi ale pořád jedna nejasnost - jaktože to > windowsářům tu výjimku nehází? Je tam jiné hashování+dict a je potřeba > zvolit jiné názvy proměnných? > > Tak jestli to dobře chápu, tak záleží na tom, v jakém pořadí jsou proměnné uložené ve slovníku. A ve windows se to pravděpodobně řadí v tom správném pořadí (pro tento příklad). Myslím že Petr Přikryl tu jednou ukazoval, že u slovníku skutečně záleží na volbě klíče (v tomto případě je to název proměnné) - podle toho se pak řadí do slovníku jednotlivé položky.
-- geon Pavel Kosina _______________________________________________ Python mailing list [email protected] http://www.py.cz/mailman/listinfo/python
