Re: It is __del__ calling twice for some instances?

2006-08-18 Thread Duncan Booth
Max Yuzhakov wrote: Why for some instance __del__ called twice? Such behaviour of __del__ seems to me unpredictable. Here's a slightly modified version of your code. The 51st object destroyed gets its __del__ method called twice. It doesn't matter how long your loop is, every 50th object

Re: It is __del__ calling twice for some instances?

2006-08-18 Thread Duncan Booth
Duncan Booth wrote: As to why it happens, there is a mechanism in Python to stop unlimited stack being used when objects are freed: when the stack gets too deep then instead of being released, the Py_DECREF call puts the object into a trashcan list and the objects aren't released until the

Re: It is __del__ calling twice for some instances?

2006-08-18 Thread Patrick Maupin
Duncan Booth wrote: Duncan Booth wrote: As to why it happens, there is a mechanism in Python to stop unlimited stack being used when objects are freed: when the stack gets too deep then instead of being released, the Py_DECREF call puts the object into a trashcan list and the objects

Re: It is __del__ calling twice for some instances?

2006-08-18 Thread Max Yuzhakov
Duncan Booth wrote: DB I figured out what is going on in the code to deallocate an old-style class DB instance: DB DB The reference count is temporarily incremented. DB DB If the class has a __del__ method then a descriptor is created for the DB method and called. When the call

Re: It is __del__ calling twice for some instances?

2006-08-18 Thread Max Yuzhakov
Duncan Booth wrote: DB BTW, the behaviour is completely different if you use a new style class, DB but still somewhat bizarre: for new style classes only the first 25 objects DB get freed when you clear a, the remainder are only released by the garbage DB collector. If to add the

Re: It is __del__ calling twice for some instances?

2006-08-17 Thread Max Yuzhakov
Duncan Booth wrote: DB You should post a working code sample which generates your output if you DB want a more useful answer. Hello! Today I have found a compact variant of a code which shows my question: ---

It is __del__ calling twice for some instances?

2006-08-16 Thread Max Yuzhakov
Hello! It is correct behaviour for python to call __del__ on some identity of a class object more than once? In brief I shall describe a situation. Sorry for my english. For debugin purposes I'm put in my module global counters for counting __init__ and __del__ calls. This is a sample code for

Re: It is __del__ calling twice for some instances?

2006-08-16 Thread Max Yuzhakov
Max Yuzhakov writes: MY print difference = %d % init_cnt-del_cnt Little correction. print difference = %d % (init_cnt-del_cnt) -- GMT More Then ... -- http://mail.python.org/mailman/listinfo/python-list

Re: It is __del__ calling twice for some instances?

2006-08-16 Thread Fredrik Lundh
Max Yuzhakov wrote: This is a sample code for clearness: that code snippet doesn't create any foo() instances, what I can see... /F -- http://mail.python.org/mailman/listinfo/python-list

Re: It is __del__ calling twice for some instances?

2006-08-16 Thread Duncan Booth
Max Yuzhakov wrote: It is correct behaviour for python to call __del__ on some identity of a class object more than once? Not with the code which you gave as an example, but in the general case yes, the only guarantee that Python gives about the __del__ method on an instance is that it will

Re: It is __del__ calling twice for some instances?

2006-08-16 Thread Max Yuzhakov
Duncan Booth пишет: DB Not with the code which you gave as an example, but in the general case DB yes, the only guarantee that Python gives about the __del__ method on an DB instance is that it will be called zero, one or more than one times during DB the run of the program. In