Re: [Python-Dev] Cycle collection enhancement idea

2008-06-29 Thread [EMAIL PROTECTED]
On Jun 28, 6:21 pm, Nick Coghlan <[EMAIL PROTECTED]> wrote: > Eyal Lotem wrote: > > Example: > > > import os > > class RunningFile(object): > >     filename = '/tmp/running' > >     def __init__(self): > >         open(self.filename, 'wb') > >     def __del__(self): > >         os.unlink(self.filen

Re: [Python-Dev] Cycle collection enhancement idea

2008-06-29 Thread [EMAIL PROTECTED]
On Jun 28, 6:32 pm, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote: > > Example: > > > import os > > class RunningFile(object): > >     filename = '/tmp/running' > >     def __init__(self): > >         open(self.filename, 'wb') > >     def __del__(self): > >         os.unlink(self.filename) > > runnin

Re: [Python-Dev] Cycle collection enhancement idea

2008-06-29 Thread [EMAIL PROTECTED]
On Jun 29, 7:52 am, "Guido van Rossum" <[EMAIL PROTECTED]> wrote: > On Sat, Jun 28, 2008 at 5:39 PM, Greg Ewing <[EMAIL PROTECTED]> wrote: > > Nick Coghlan wrote: > > >> It's a fact of Python development: __del__ methods cannot safely reference > >> module globals, because those globals may be gone

Re: [Python-Dev] Cycle collection enhancement idea

2008-06-29 Thread Antoine Pitrou
eyal.lotem+pyutils gmail.com gmail.com> writes: > This is exactly what my post tried to address. > I assumed it was clear that module clearing is the wrong solution, and > that it was also clear that due to the cycles I mentioned > (global.__class__.__dict__['any_method'].func_globals['global'] i

Re: [Python-Dev] Cycle collection enhancement idea

2008-06-29 Thread [EMAIL PROTECTED]
On Jun 29, 3:04 pm, Antoine Pitrou <[EMAIL PROTECTED]> wrote: > eyal.lotem+pyutils gmail.com gmail.com> writes: > > > This is exactly what my post tried to address. > > I assumed it was clear that module clearing is the wrong solution, and > > that it was also clear that due to the cycles I menti

Re: [Python-Dev] Cycle collection enhancement idea

2008-06-29 Thread Antoine Pitrou
eyal.lotem+pyutils gmail.com gmail.com> writes: > > That would be no worse than what happens now - but its still not > perfect (__del__ ordering issues). Also, you would need to temporarily > revive the cycles as mentioned above (to avoid accessibility of > partially destructed objects). The id

Re: [Python-Dev] Cycle collection enhancement idea

2008-06-29 Thread [EMAIL PROTECTED]
On Jun 29, 3:36 pm, Antoine Pitrou <[EMAIL PROTECTED]> wrote: > eyal.lotem+pyutils gmail.com gmail.com> writes: > > > > > That would be no worse than what happens now - but its still not > > perfect (__del__ ordering issues). Also, you would need to temporarily > > revive the cycles as mentioned

Re: [Python-Dev] Cycle collection enhancement idea

2008-06-29 Thread [EMAIL PROTECTED]
On Jun 29, 5:12 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > On Jun 29, 3:36 pm, Antoine Pitrou <[EMAIL PROTECTED]> wrote: > > > eyal.lotem+pyutils gmail.com gmail.com> writes: > > > > That would be no worse than what happens now - but its still not > > > perfect (__del__ ordering issues)

Re: [Python-Dev] Cycle collection enhancement idea

2008-06-29 Thread Antoine Pitrou
eyal.lotem+pyutils gmail.com gmail.com> writes: > > Additionally, there is another problem: If the cycle is not > temporarily revived, and you call __del__ manually, it may break the > cycle by removing the references. > Thus, objects in the cycle will go down to refcount=0 during your > attempt

Re: [Python-Dev] Cycle collection enhancement idea

2008-06-29 Thread Antoine Pitrou
Antoine Pitrou pitrou.net> writes: > > I was thinking a flag in the PyObject header would do the trick but there > aren't any flags in the PyObject header... *gasp*. Actually, we only care about GC-tracked objects (the others are deallocated simply when their refcount falls to zero), so this cou

Re: [Python-Dev] GC Proposal

2008-06-29 Thread Adam Olsen
On Sun, Jun 29, 2008 at 12:59 AM, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote: >> Looks about equivalent, but "survivors" may mean two different things >> depending on if it removes deleted survivors or not. Splitting that >> up, we get this form: >> >> old <= survivors * 2.0 + deleted * 1.0 > > W

Re: [Python-Dev] Cycle collection enhancement idea

2008-06-29 Thread Adam Olsen
On Sat, Jun 28, 2008 at 10:52 PM, Guido van Rossum <[EMAIL PROTECTED]> wrote: > On Sat, Jun 28, 2008 at 5:39 PM, Greg Ewing <[EMAIL PROTECTED]> wrote: >> Nick Coghlan wrote: >> >>> It's a fact of Python development: __del__ methods cannot safely reference >>> module globals, because those globals m

Re: [Python-Dev] GC Proposal

2008-06-29 Thread Martin v. Löwis
>> What precisely would be the "deleted" count? If it counts deallocations, >> is it relevant what generation the deallocated object was from? >> If so, how do you determine the generation? If not, wouldn't >> >> while 1: >> x=[] >> >> trigger a full garbage collection fairly quickly? > > "delet

Re: [Python-Dev] Cycle collection enhancement idea

2008-06-29 Thread Martin v. Löwis
> As I explained above, it *is* part of a cycle: """including > the class objects themselves: class->dict->function->func_globals""". Ah, right. I must have missed that explanation. > I know. I assumed Python does not rely on cyclic garbage collectioin > for shutdown, because it wouldn't work, as

Re: [Python-Dev] Cycle collection enhancement idea

2008-06-29 Thread Martin v. Löwis
> That would be no worse than what happens now - but its still not > perfect (__del__ ordering issues). Also, you would need to temporarily > revive the cycles as mentioned above (to avoid accessibility of > partially destructed objects). I don't quite understand what you mean by "revive cycles".

Re: [Python-Dev] Cycle collection enhancement idea

2008-06-29 Thread Martin v. Löwis
> Firstly, as I said above: you will still have __del__ ordering issues. Can you please elaborate? What would such __del__ ordering issues be? > Secondly, the destructor itself currently calls __del__, so if you > call __del__ before any deallocation, it will get called again as part > of the dea

Re: [Python-Dev] Cycle collection enhancement idea

2008-06-29 Thread Martin v. Löwis
> Additionally, there is another problem: If the cycle is not > temporarily revived, and you call __del__ manually, it may break the > cycle by removing the references. > Thus, objects in the cycle will go down to refcount=0 during your > attempt to call __del__'s on the objects in the cycle. > The

Re: [Python-Dev] Cycle collection enhancement idea

2008-06-29 Thread Eyal Lotem
On Sun, Jun 29, 2008 at 9:00 PM, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote: >> As I explained above, it *is* part of a cycle: """including >> the class objects themselves: class->dict->function->func_globals""". > > Ah, right. I must have missed that explanation. > >> I know. I assumed Python doe

Re: [Python-Dev] GC Proposal

2008-06-29 Thread Adam Olsen
On Sun, Jun 29, 2008 at 11:49 AM, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote: > >>> What precisely would be the "deleted" count? If it counts deallocations, >>> is it relevant what generation the deallocated object was from? >>> If so, how do you determine the generation? If not, wouldn't >>> >>>

Re: [Python-Dev] Cycle collection enhancement idea

2008-06-29 Thread Martin v. Löwis
> By "revive cycles", I mean make sure that they are referenced by an > independent referrer (one that won't go away as part of the __del__ > calling process). I think this is a) unfortunate terminology (as the cycle is not dead, so no need to revive), and b) unnecessary, as calling __del__ will a

Re: [Python-Dev] [Python-checkins] r64424 - inpython/trunk:Include/object.h Lib/test/test_sys.pyMisc/NEWSObjects/intobject.c Objects/longobject.cObjects/typeobject.cPython/bltinmodule.c

2008-06-29 Thread Mark Dickinson
On Sun, Jun 29, 2008 at 12:46 AM, Raymond Hettinger <[EMAIL PROTECTED]> wrote: > Is everyone agreed on a tohex/fromhex pair using the C99 notation as > recommended in 754R? Sounds good to me. I've attached a Python version of a possible implementation to the issue. See: http://bugs.python.org/fi

Re: [Python-Dev] Cycle collection enhancement idea

2008-06-29 Thread Greg Ewing
Since it's already possible for __del__-containing cycles to survive interpreter shutdown, I don't see that this issue ought to be a showstopper for elimination of module clearing. Also, it seems to me that the kind of cycles module clearing is designed to break, i.e. those between classes, funct