Lawrence Oluyede ha scritto: >> Tempo fa Michele Simionato aveva postato (non su questa mailing list) >> questo script: >> >> import logging >> import threading >> >> class C(object): >> def __init__(self): >> print threading.currentThread() >> >> def __del__(self): >> print threading.currentThread() >> logging.warn('deleted %r' % self) >> >> if __name__ == '__main__': >> c = C() >> >> >> >>> $python logbug.py >>> <_MainThread(MainThread, started)> >>> <_DummyThread(Dummy-1, started daemon)> >>> Exception exceptions.AttributeError: "'NoneType' object has no attribute >>> 'warn'" in <bound method C.__del__ of <__main__.C object at 0xb7da310c>> >>> ignored > > Direi che in questo caso e` un non problema pero`... __del__ e` come la peste > ;) > >
Hai ragione, ho ricontrollato lo script e la colpa non è del modulo logging. Evidentemente quando vengono invocati i distruttori degli oggetti nello scope globale, succedono cose strane :) Se l'istruzione c = C() si mette in una funzione, va tutto bene. Infine, anche se threading.currentThread() restituisce due valori diversi, il thread "fisico" è sempre lo stesso (basta usare thread.get_ident). Manlio Perillo _______________________________________________ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python