Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Mark Lawrence
On 05/03/18 01:01, Ooomzay wrote: On Sunday, 4 March 2018 23:57:24 UTC, Mark Lawrence wrote: On 04/03/18 02:28, Ooomzay wrote: On Friday, 2 March 2018 15:37:25 UTC, Paul Moore wrote: [snip] def fn(): for i in range(1): with open(f"file{i}.txt", "w") as f:

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Ooomzay
On Monday, 5 March 2018 01:11:43 UTC, Richard Damon wrote: > On 3/4/18 6:55 PM, Ned Batchelder wrote: > > On 3/4/18 5:25 PM, Ooomzay wrote: > >> On Sunday, 4 March 2018 14:37:30 UTC, Ned Batchelder  wrote: > >>> Are you including cyclic references in your assertion that CPython > >>> behaves as yo

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Ben Finney
Richard Damon writes: > […] I can't see any good way to create the equivalent of a 'weak > reference' (names aren't objects so don't have properties). The  best > I can think of is to create some sort of magical object that can refer > to another object, but that reference 'doesn't count'. This s

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Ooomzay
On Saturday, 3 March 2018 17:10:53 UTC, Dietmar Schwertberger wrote: > CPython does *not* guarantee destruction when the object reference goes > out of scope, even if there are no other references. > I would very much appreciate such a deterministic behaviour, at least > with CPython. > > I rec

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Richard Damon
On 3/4/18 6:55 PM, Ned Batchelder wrote: On 3/4/18 5:25 PM, Ooomzay wrote: On Sunday, 4 March 2018 14:37:30 UTC, Ned Batchelder  wrote: Are you including cyclic references in your assertion that CPython behaves as you want? Yes. Because the only behaviour required for RAII is to detect and deb

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Ooomzay
On Sunday, 4 March 2018 23:55:33 UTC, Ned Batchelder wrote: > On 3/4/18 5:25 PM, Ooomzay wrote: > > On Sunday, 4 March 2018 14:37:30 UTC, Ned Batchelder wrote: > >> Are you including cyclic references in your assertion that CPython > >> behaves as you want? > > Yes. Because the only behaviour req

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Ooomzay
On Sunday, 4 March 2018 23:57:24 UTC, Mark Lawrence wrote: > On 04/03/18 02:28, Ooomzay wrote: > > On Friday, 2 March 2018 15:37:25 UTC, Paul Moore wrote: > > [snip] > >> def fn(): > >> for i in range(1): > >> with open(f"file{i}.txt", "w") as f: > >>

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Ooomzay
On Sunday, 4 March 2018 15:24:08 UTC, Steven D'Aprano wrote: > On Sun, 04 Mar 2018 03:37:38 -0800, Ooomzay wrote: > > > Please consider the case of a composite resource: You need to implement > > __enter__, __exit__ and track the open/closed state at every level in > > your component hierarchy -

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Mark Lawrence
On 04/03/18 02:28, Ooomzay wrote: On Friday, 2 March 2018 15:37:25 UTC, Paul Moore wrote: [snip] def fn(): for i in range(1): with open(f"file{i}.txt", "w") as f: f.write("Some text") How would you write this in your RAII style - without leaving

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Chris Angelico
On Sun, Mar 4, 2018 at 10:37 PM, Ooomzay wrote: > Please consider the case of a composite resource: You need to implement > __enter__, __exit__ and track the open/closed state at every level in > your component hierarchy - even if some levels hold no resources directly. > > This is burdensome, bre

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Dietmar Schwertberger
On 3/4/2018 1:37 PM, Ooomzay wrote: Not so:- CPython, the reference interpreter, already implements the required behaviour, as mentioned in the PEP. It does most of the time, but it's not guaranteed. See my previous post. Regards, Dietmar -- https://mail.python.org/mailman/listinfo/python-

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Ned Batchelder
On 3/4/18 5:25 PM, Ooomzay wrote: On Sunday, 4 March 2018 14:37:30 UTC, Ned Batchelder wrote: Are you including cyclic references in your assertion that CPython behaves as you want? Yes. Because the only behaviour required for RAII is to detect and debug such cycles in order to eliminate them

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Chris Angelico
On Mon, Mar 5, 2018 at 10:42 AM, Steven D'Aprano wrote: > On Mon, 05 Mar 2018 09:20:24 +1100, Chris Angelico wrote: > >> Okay, that sounds reasonable. Let's help things out by creating a >> special syntax for reference-counted object usage > [...] >> Feel free to bikeshed the exact keywords and fu

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Steven D'Aprano
On Mon, 05 Mar 2018 09:20:24 +1100, Chris Angelico wrote: > Okay, that sounds reasonable. Let's help things out by creating a > special syntax for reference-counted object usage [...] > Feel free to bikeshed the exact keywords and function names, of course. I see what you did there. :-) -- S

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Ooomzay
On Sunday, 4 March 2018 14:37:30 UTC, Ned Batchelder wrote: > Are you including cyclic references in your assertion that CPython > behaves as you want? Yes. Because the only behaviour required for RAII is to detect and debug such cycles in order to eliminate them. It is a design error/resource

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Chris Angelico
On Mon, Mar 5, 2018 at 9:09 AM, Richard Damon wrote: > My presumption of the proposal is the it does NOT expect that __del__ be > called just because an object is no longer reachable but is in a cycle of > isolated objects, those would still need to wait for the garbage collector > to get them. Th

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Richard Damon
On 3/4/18 8:46 AM, Chris Angelico wrote: On Mon, Mar 5, 2018 at 12:26 AM, Ooomzay wrote: Well refcounts are definitely "doable": This is how the reference python implementation, CPython, currently manages to comply with this PEP and can therefore be used for RAII. This PEP is an attempt to _g

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread bartc
On 04/03/2018 14:11, Ooomzay wrote: Well I see a lot of posts that indicate peeps here are more comfortable with the "with" idiom than the RAII idiom but I have not yet seen a single linguistic problem or breakage. As it happens I have used RAII extensively with CPython to manage a debugging e

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Ned Batchelder
On 3/4/18 9:11 AM, Ooomzay wrote: I am well aware of what it will mean for interpreters. For some interpreters it will have zero impact (e.g. CPython) ... There's no point continuing this if you are just going to insist on falsehoods like this.  CPython doesn't currently do what you want, but

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Steven D'Aprano
On Sun, 04 Mar 2018 09:37:34 -0500, Ned Batchelder wrote: > On 3/4/18 7:37 AM, Ooomzay wrote: >> On Sunday, 4 March 2018 04:23:07 UTC, Steven D'Aprano wrote: >>> [...] >>> [This PEP] imposes enormous burdens on the maintainers of at least >>> five interpreters (CPython, Stackless, Jython, IronPyt

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Steven D'Aprano
On Sun, 04 Mar 2018 03:37:38 -0800, Ooomzay wrote: > Please consider the case of a composite resource: You need to implement > __enter__, __exit__ and track the open/closed state at every level in > your component hierarchy - even if some levels hold no resources > directly. I'm sorry, that descr

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Ned Batchelder
On 3/4/18 7:37 AM, Ooomzay wrote: On Sunday, 4 March 2018 04:23:07 UTC, Steven D'Aprano wrote: [...] [This PEP] imposes enormous burdens on the maintainers of at least five interpreters (CPython, Stackless, Jython, IronPython, PyPy) all of which will need to be re-written to have RAII semantics

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Ned Batchelder
On 3/4/18 8:26 AM, Ooomzay wrote: On Sunday, 4 March 2018 03:16:31 UTC, Paul Rubin wrote: Chris Angelico writes: Yep, cool. Now do that with all of your smart pointers being on the heap too. You are not allowed to use ANY stack objects. ANY. Got it? That's both overconstraining and not even

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Chris Angelico
On Mon, Mar 5, 2018 at 1:11 AM, Ooomzay wrote: > On Sunday, 4 March 2018 03:00:13 UTC, Chris Angelico wrote: >> This thread is dead. The OP wants to wave a magic wand and say >> "__del__ is now guaranteed to be called immediately", > > No "magic" required: Just one line change in the language ref

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Ooomzay
On Sunday, 4 March 2018 03:00:13 UTC, Chris Angelico wrote: > This thread is dead. The OP wants to wave a magic wand and say > "__del__ is now guaranteed to be called immediately", No "magic" required: Just one line change in the language reference will do it. > without any explanation The PEP

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Steven D'Aprano
On Sun, 04 Mar 2018 04:37:46 -0800, Ooomzay wrote: > On Sunday, 4 March 2018 04:23:07 UTC, Steven D'Aprano wrote: >> [...] >> [This PEP] imposes enormous burdens on the maintainers of at least five >> interpreters (CPython, Stackless, Jython, IronPython, PyPy) all of >> which will need to be re-w

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Chris Angelico
On Mon, Mar 5, 2018 at 12:26 AM, Ooomzay wrote: > Well refcounts are definitely "doable": This is how the reference python > implementation, CPython, currently manages to comply with this PEP and can > therefore be used for RAII. > > This PEP is an attempt to _guarantee_ this behaviour and make t

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Ooomzay
On Sunday, 4 March 2018 03:16:31 UTC, Paul Rubin wrote: > Chris Angelico writes: > > Yep, cool. Now do that with all of your smart pointers being on the > > heap too. You are not allowed to use ANY stack objects. ANY. Got it? > > That's both overconstraining and not even that big a problem the

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Ooomzay
On Sunday, 4 March 2018 04:23:07 UTC, Steven D'Aprano wrote: > [...] > [This PEP] imposes enormous burdens on the maintainers of at least five > interpreters (CPython, Stackless, Jython, IronPython, PyPy) all of which > will need to be re-written to have RAII semantics guaranteed; Not so:- CP

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Ooomzay
On Sunday, 4 March 2018 04:23:07 UTC, Steven D'Aprano wrote: > On Sat, 03 Mar 2018 18:19:37 -0800, Ooomzay wrote: > > >> def function(): > >> x = open_resource() > >> process(x) > >> # and we're done with x now, but too lazy to explicitly close it > >> sleep(1) # Simulate some