Unexpected exception thrown in __del__
Jean-Michel Pichavant
jeanmichel at sequans.com
Tue May 22 06:56:26 EDT 2012
Charles Hixson wrote:
> On 05/21/2012 08:29 AM, Charles Hixson wrote:
>> message excerpt:
>> flush: sql = insert or replace into persists (id, name, data, rdCnt,
>> rdTim, wrCnt, wrTim, deprecation) values (?, ?, ?, ?, ?, ?, ?, ?)
>> Exception TypeError: "'NoneType' object is not callable" in <bound
>> method Shelve2.__del__ of <__main__.Shelve2 object at
>> 0x7ff4c0513f90>> ignored
>>
>> flush is being called from within __del__. I've narrowed it down to:
>> print ("flush: sql = ", sql)
>> curTim = nowI()
>> print ("flush: curTim = ", curTim)
>>
>> nowI() is a function defined at the top of the file, and before the
>> class, thus:
>> def nowI():
>> t = int (time() * 100)
>> return t
>>
>> All I can guess is that there's some reason that an external to the
>> class function shouldn't be called during a __del__. Is this correct?
>>
> That seems to be the answer, as replacing the call to nowI() in
> flush() with:
> curTim = int (time() * 100)
> fixes the problem.
>
> Rereading the documentation, I guess that this should have been
> expected, but if nowI() were a static method of the class, would that
> have avoided the problem? A class method?
>
>
I may be stating somthing you already know, sorry if it happends.
__del__ is *not* executed upon a del statement, so I hope you don't have
any del(obj) assuming __del__ will be called. That is not true.
__del__ is called when there's no reference to an object any more, *AND*
when the python implementation feels in the mood for it, which is
specific to that implemenation.
There's a chance that a class method won't fix anything, if it does,
it's not reliable anyway.
Cheers,
JM
More information about the Python-list
mailing list