Re: RFC: Proposal: Deterministic Object Destruction (Posting On Python-List Prohibited)

2018-03-07 Thread Chris Angelico
On Thu, Mar 8, 2018 at 5:17 AM, Ooomzay wrote: > On Thursday, 1 March 2018 22:44:59 UTC, Rob Gaddi wrote: >> On 03/01/2018 02:24 PM, Lawrence D’Oliveiro wrote: >> > On Thursday, March 1, 2018 at 6:44:39 PM UTC+13, Paul Rubin wrote: >> >> DOM trees are a classic example (see

Re: RFC: Proposal: Deterministic Object Destruction (Posting On Python-List Prohibited)

2018-03-07 Thread Ooomzay
On Thursday, 1 March 2018 22:44:59 UTC, Rob Gaddi wrote: > On 03/01/2018 02:24 PM, Lawrence D’Oliveiro wrote: > > On Thursday, March 1, 2018 at 6:44:39 PM UTC+13, Paul Rubin wrote: > >> DOM trees are a classic example (see the various DOM modules in the > >> Python stdlib). Non-leaf nodes have a

Re: Layers of abstraction, was Re: RFC: Proposal: Deterministic Object Destruction

2018-03-06 Thread Ooomzay
On Wednesday, 7 March 2018 06:43:10 UTC, Ooomzay wrote: > On Tuesday, 6 March 2018 14:12:38 UTC, Peter Otten wrote: > > Chris Angelico wrote: > > > > > On Tue, Mar 6, 2018 at 10:04 AM, Steven D'Aprano > > > wrote: > > >> # Later. > > >> if __name__ =

Re: Layers of abstraction, was Re: RFC: Proposal: Deterministic Object Destruction

2018-03-06 Thread Ooomzay
On Tuesday, 6 March 2018 14:12:38 UTC, Peter Otten wrote: > Chris Angelico wrote: > > > On Tue, Mar 6, 2018 at 10:04 AM, Steven D'Aprano > > wrote: > >> # Later. > >> if __name__ = '__main__': > >> # Enter the Kingdom of Nouns. > > > > Don't you need a

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-06 Thread Steven D'Aprano
On Tue, 06 Mar 2018 14:09:53 -0800, Ooomzay wrote: > Unfortunately, despite having conquered it, without a _guarantee_ of > this behaviour from the language, or at least one mainstream > implementation, I will not invest in python again. Oh well, so sad. See you later. -- Steve --

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-06 Thread Chris Angelico
On Wed, Mar 7, 2018 at 9:09 AM, Ooomzay wrote: >> I'm not trying to dissuade you from using RAII in your own applications, >> if it works for you, great. > > Unfortunately, despite having conquered it, without a _guarantee_ of this > behaviour from the language, or at least one

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-06 Thread Ooomzay
On Monday, 5 March 2018 23:06:53 UTC, Steven D'Aprano wrote: > On Mon, 05 Mar 2018 09:22:33 -0800, Ooomzay wrote: > [...] > > If you would like to have a shot at coding this without RAII, but > > preserving the OO design, you will find that it is considerably > > simpler than the with/context

Layers of abstraction, was Re: RFC: Proposal: Deterministic Object Destruction

2018-03-06 Thread Peter Otten
Chris Angelico wrote: > On Tue, Mar 6, 2018 at 10:04 AM, Steven D'Aprano > wrote: >> # Later. >> if __name__ = '__main__': >> # Enter the Kingdom of Nouns. > > Don't you need a NounKingdomEnterer to do that for you? No, for some extra flexibility there

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-05 Thread Chris Angelico
On Tue, Mar 6, 2018 at 10:04 AM, Steven D'Aprano wrote: > # Later. > if __name__ = '__main__': > # Enter the Kingdom of Nouns. Don't you need a NounKingdomEnterer to do that for you? ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-05 Thread Steven D'Aprano
On Mon, 05 Mar 2018 09:22:33 -0800, Ooomzay wrote: [...] >> Looking at that code, my major thought is that there is far too much >> OO design, not enough simplicity. > > If this is far too much OO for you then RAII will be of no interest to > you. I think this is probably the wisest thing you

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-05 Thread Ooomzay
On Monday, 5 March 2018 19:14:05 UTC, Paul Rubin wrote: > Ooomzay writes: > > If you want to use RAII objects then you will make sure you avoid > > adding them to orphan cycles by design. If you don't know how to do > > that then don't write applications that manage critical resources. > > My

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-05 Thread Ooomzay
On Monday, 5 March 2018 17:58:40 UTC, Chris Angelico wrote: > On Tue, Mar 6, 2018 at 4:53 AM, Ooomzay wrote: > > On Monday, 5 March 2018 14:21:54 UTC, Chris Angelico wrote: > >> On Tue, Mar 6, 2018 at 12:58 AM, Ooomzay wrote: > >> > Here is my fixed example, if someone else could try it in

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-05 Thread Chris Angelico
On Tue, Mar 6, 2018 at 4:53 AM, Ooomzay wrote: > On Monday, 5 March 2018 14:21:54 UTC, Chris Angelico wrote: >> On Tue, Mar 6, 2018 at 12:58 AM, Ooomzay wrote: >> > Here is my fixed example, if someone else could try it in CPython and >> > report back that would be

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-05 Thread Ooomzay
On Monday, 5 March 2018 14:21:54 UTC, Chris Angelico wrote: > On Tue, Mar 6, 2018 at 12:58 AM, Ooomzay wrote: > > Here is my fixed example, if someone else could try it in CPython and > > report back that would be interesting:- > > > > class RAIIFileAccess(): > > def __init__(self, fname): >

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-05 Thread Ooomzay
On Monday, 5 March 2018 16:47:02 UTC, Steven D'Aprano wrote: > On Sun, 04 Mar 2018 16:58:38 -0800, Ooomzay wrote: > > > Here is an example of a composite resource using RAII:- > > > > class RAIIFileAccess(): > > def __init__(self, fname): > > print("%s Opened" % fname) > > def

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-05 Thread Steven D'Aprano
On Mon, 05 Mar 2018 07:31:57 -0800, Ooomzay wrote: > We do not expect this to work in PyPy. Or Jython, IronPython, possibly not Stackless either, or in the interactive interpreter of (probably) any implementation, or CPython if the object is garbage collected during interpreter shutdown or is

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-05 Thread Steven D'Aprano
On Sun, 04 Mar 2018 16:58:38 -0800, Ooomzay wrote: > Here is an example of a composite resource using RAII:- > > class RAIIFileAccess(): > def __init__(self, fname): > print("%s Opened" % fname) > def __del__(self): > print("%s Closed" % fname) > > class A(): > def

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-05 Thread Ooomzay
On Monday, 5 March 2018 15:17:13 UTC, bartc wrote: > On 05/03/2018 13:58, Ooomzay wrote: > > On Monday, 5 March 2018 11:24:37 UTC, Chris Angelico wrote: > >> On Mon, Mar 5, 2018 at 10:09 PM, Ooomzay wrote: > >>> Here is an example of a composite resource using RAII:- > >>> > >>> class

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-05 Thread bartc
On 05/03/2018 13:58, Ooomzay wrote: On Monday, 5 March 2018 11:24:37 UTC, Chris Angelico wrote: On Mon, Mar 5, 2018 at 10:09 PM, Ooomzay wrote: Here is an example of a composite resource using RAII:- class RAIIFileAccess(): def __init__(self, fname): print("%s Opened" % fname)

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-05 Thread Ooomzay
On Monday, 5 March 2018 14:36:30 UTC, Chris Angelico wrote: > On Tue, Mar 6, 2018 at 1:25 AM, Ooomzay wrote: > > Ahah... I see now you are running it from a shell so the exception is > > staying in scope. We just need to include normal exception handling in the > > example to fix this:- > > > >

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-05 Thread Chris Angelico
On Tue, Mar 6, 2018 at 1:25 AM, Ooomzay wrote: > Ahah... I see now you are running it from a shell so the exception is staying > in scope. We just need to include normal exception handling in the example to > fix this:- > > def main(): > try: > c = C() >

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-05 Thread Ooomzay
On Monday, 5 March 2018 13:59:35 UTC, Ooomzay wrote: > On Monday, 5 March 2018 11:24:37 UTC, Chris Angelico wrote: > > On Mon, Mar 5, 2018 at 10:09 PM, Ooomzay wrote: > > > Here is an example of a composite resource using RAII:- > > > > > > class RAIIFileAccess(): > > > def __init__(self,

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-05 Thread Chris Angelico
On Tue, Mar 6, 2018 at 12:58 AM, Ooomzay wrote: > Then that is indeed a challenge. From CPython back in 2.6 days up to > Python36-32 what I see is:- > > a Opened > b Opened > Traceback (most recent call last): > ... > AttributeError: 'C' object has no attribute 'dostuff' > a

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-05 Thread Ooomzay
On Monday, 5 March 2018 11:24:37 UTC, Chris Angelico wrote: > On Mon, Mar 5, 2018 at 10:09 PM, Ooomzay wrote: > > Here is an example of a composite resource using RAII:- > > > > class RAIIFileAccess(): > > def __init__(self, fname): > > print("%s Opened" % fname) > > def

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-05 Thread Chris Angelico
On Mon, Mar 5, 2018 at 10:09 PM, Ooomzay wrote: > Here is an example of a composite resource using RAII:- > > class RAIIFileAccess(): > def __init__(self, fname): > print("%s Opened" % fname) > def __del__(self): > print("%s Closed" % fname) > > class

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-05 Thread Ooomzay
On Sunday, 4 March 2018 23:56:09 UTC, Chris Angelico wrote: > 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

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-05 Thread Ooomzay
On Monday, March 5, 2018 at 6:38:49 AM UTC, Mark Lawrence wrote: > 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

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

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

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

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

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

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

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. > >

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 --

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

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

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. :-) --

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

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

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

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,

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,

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

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

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

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

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

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: 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

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

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:-

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

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread Steven D'Aprano
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 more work. Lots of work. >> return >> # and finally x is closed

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread Steven D'Aprano
On Sat, 03 Mar 2018 08:02:35 -0800, ooomzay wrote: [...] >> > But I am not! On the contrary RAII frees the programmer from even >> > having to remember to close the file. The poster asked what would >> > happen if the resource was deliberately kept open by storing a >> > reference at global

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread Chris Angelico
On Sun, Mar 4, 2018 at 1:45 PM, Ooomzay wrote: > On Sunday, 4 March 2018 01:58:02 UTC, Gregory Ewing wrote: >> ooomzay wrote: >> > Well he was not telling you the whole story: RAII works just as well with >> > heap objects using smart pointers (unique_ptr and friends) which

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread Ooomzay
On Sunday, 4 March 2018 01:58:02 UTC, Gregory Ewing wrote: > ooomzay wrote: > > Well he was not telling you the whole story: RAII works just as well with > > heap objects using smart pointers (unique_ptr and friends) which are a > > closer > > analogy to python object references. > > By that

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread Richard Damon
On 3/3/18 9:10 PM, Chris Angelico wrote: On Sun, Mar 4, 2018 at 1:01 PM, Ooomzay wrote: On Saturday, 3 March 2018 17:44:08 UTC, Chris Angelico wrote: On Sun, Mar 4, 2018 at 4:37 AM, Richard Damon Yes, stack allocated object in C++ have a nice

Re: RFC: Proposal: Deterministic Object Destruction (Posting On Python-List Prohibited)

2018-03-03 Thread Gregory Ewing
Richard Damon wrote: The idea was to have a way to mark that certain classes/objects request that they are reference counted so they get the __del__ called as soon as the last reference goes away, without needing to require that overhead for all objects in all implementations. That could be

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread Ooomzay
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 10,000 > file descriptors

Re: RFC: Proposal: Deterministic Object Destruction (Posting On Python-List Prohibited)

2018-03-03 Thread Gregory Ewing
Steven D'Aprano wrote: Not just the class __dict__. You would have to do a full search of the MRO looking for any superclass which defines such methods. That could be reduced a lot by making it a type slot. But it would still increase the overhead of every refcount change by at least a factor

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread Ooomzay
On Saturday, 3 March 2018 23:52:34 UTC, Steven D'Aprano wrote: > I know that laziness and hubris are programmer virtues, but there is > still such a thing as *too much laziness*. RAII works in C++ where > instances are allocated in the stack, but even there, if you have an > especially

Re: RFC: Proposal: Deterministic Object Destruction (Posting On Python-List Prohibited)

2018-03-03 Thread Gregory Ewing
Paul Rubin wrote: Richard Damon writes: a class to define member functions like __ref__ and __unref__ (or perhaps some other name) that if defined, would be called every time a name was bound or unbound to an object? That sounds horrendous and wouldn't handle the

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread Chris Angelico
On Sun, Mar 4, 2018 at 1:01 PM, Ooomzay wrote: > On Saturday, 3 March 2018 17:44:08 UTC, Chris Angelico wrote: >> On Sun, Mar 4, 2018 at 4:37 AM, Richard Damon >> > Yes, stack allocated object in C++ have a nice lifetime to allow RAII to >> > work,

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread Ooomzay
On Saturday, 3 March 2018 17:44:08 UTC, Chris Angelico wrote: > On Sun, Mar 4, 2018 at 4:37 AM, Richard Damon > > Yes, stack allocated object in C++ have a nice lifetime to allow RAII to > > work, but it doesn't just work with stack allocated objects. A lot of RAII > >

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread Ooomzay
On Saturday, 3 March 2018 17:16:14 UTC, Ned Batchelder wrote: > On 3/2/18 10:36 AM, Paul Moore wrote: > > Or (real Python): > > > > def fn(): > > for i in range(1): > > with open(f"file{i}.txt", "w") as f: > > f.write("Some text") > > > > How would

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread Gregory Ewing
ooom...@gmail.com wrote: Well he was not telling you the whole story: RAII works just as well with heap objects using smart pointers (unique_ptr and friends) which are a closer analogy to python object references. By that definition, *all* resource management in Python is based on RAII[1]. The

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread ooomzay
On Friday, March 2, 2018 at 5:29:54 AM UTC, Rustom Mody wrote: > Please excuse if this has been addressed above and/or its too basic: > What's the difference between RAII and python's with/context-managers? They address the same problem but I am claiming that RAII achieves this in a

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread ooomzay
On Friday, March 2, 2018 at 3:37:25 PM UTC, Paul Moore wrote: > [...] > RAII works in C++ (where it was initially invented) because it's used > with stack-allocated variables that have clearly-defined and limited > scope. RAII also works with smart pointers, which are a closer analogue to

Re: RFC: Proposal: Deterministic Object Destruction (Posting On Python-List Prohibited)

2018-03-03 Thread Richard Damon
On 3/3/18 6:57 PM, Steven D'Aprano wrote: On Sat, 03 Mar 2018 10:01:43 -0700, Ian Kelly wrote: On Sat, Mar 3, 2018 at 9:19 AM, Richard Damon wrote: One idea does come to mind though, would it be reasonable, and somewhat Pythonic, for a class to define member

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread Richard Damon
On 3/3/18 6:49 PM, Steven D'Aprano wrote: On Sat, 03 Mar 2018 12:37:08 -0500, Richard Damon wrote: With RAII and immediate destruction on end of scope, we can automate the release, without it and you need a lot of explicit code to manage these resources. Not so much. with

Re: RFC: Proposal: Deterministic Object Destruction (Posting On Python-List Prohibited)

2018-03-03 Thread Steven D'Aprano
On Sat, 03 Mar 2018 10:01:43 -0700, Ian Kelly wrote: > On Sat, Mar 3, 2018 at 9:19 AM, Richard Damon > wrote: >> One idea does come to mind though, would it be reasonable, and somewhat >> Pythonic, for a class to define member functions like __ref__ and >> __unref__ (or

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread Steven D'Aprano
On Sat, 03 Mar 2018 12:37:08 -0500, Richard Damon wrote: > With RAII and immediate destruction on end of scope, we can automate the > release, without it and you need a lot of explicit code to manage these > resources. Not so much. with resource_i_care_about() as rsrc: process(rsrc) is

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread ooomzay
On Saturday, March 3, 2018 at 4:33:59 PM UTC, Michael Torrie wrote: > On 03/03/2018 09:02 AM, ooomzay wrote: > > I can assure you that RAII does what it says on the tin and is relied on in > > many critical systems to release resources robustly ... given the > > pre-requisite deterministic

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread Richard Damon
On 3/3/18 1:28 PM, Chris Angelico wrote: On Sun, Mar 4, 2018 at 5:22 AM, Richard Damon wrote: On 3/3/18 12:43 PM, Chris Angelico wrote: On Sun, Mar 4, 2018 at 4:37 AM, Richard Damon wrote: On 3/3/18 11:33 AM, Michael Torrie wrote: On

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread Chris Angelico
On Sun, Mar 4, 2018 at 5:22 AM, Richard Damon wrote: > On 3/3/18 12:43 PM, Chris Angelico wrote: >> >> On Sun, Mar 4, 2018 at 4:37 AM, Richard Damon >> wrote: >>> >>> On 3/3/18 11:33 AM, Michael Torrie wrote: On 03/03/2018 09:02 AM,

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread Richard Damon
On 3/3/18 12:43 PM, Chris Angelico wrote: On Sun, Mar 4, 2018 at 4:37 AM, Richard Damon wrote: On 3/3/18 11:33 AM, Michael Torrie wrote: On 03/03/2018 09:02 AM, ooom...@gmail.com wrote: I can assure you that RAII does what it says on the tin and is relied on in many

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread Chris Angelico
On Sun, Mar 4, 2018 at 4:37 AM, Richard Damon wrote: > On 3/3/18 11:33 AM, Michael Torrie wrote: >> >> On 03/03/2018 09:02 AM, ooom...@gmail.com wrote: >>> >>> I can assure you that RAII does what it says on the tin and is relied on >>> in >>> many critical systems to

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread Richard Damon
On 3/3/18 11:33 AM, Michael Torrie wrote: On 03/03/2018 09:02 AM, ooom...@gmail.com wrote: I can assure you that RAII does what it says on the tin and is relied on in many critical systems to release resources robustly ... given the pre-requisite deterministic destruction. Sure but did you

Re: RFC: Proposal: Deterministic Object Destruction (Posting On Python-List Prohibited)

2018-03-03 Thread Chris Angelico
On Sun, Mar 4, 2018 at 3:19 AM, Richard Damon wrote: > One idea does come to mind though, would it be reasonable, and somewhat > Pythonic, for a class to define member functions like __ref__ and __unref__ > (or perhaps some other name) that if defined, would be called

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread Ned Batchelder
On 2/28/18 6:53 PM, ooom...@gmail.com wrote: On Wednesday, February 28, 2018 at 11:45:24 PM UTC, ooo...@gmail.com wrote: On Wednesday, February 28, 2018 at 11:02:17 PM UTC, Chris Angelico wrote: On Thu, Mar 1, 2018 at 9:51 AM, ooomzay wrote: [snip] Taking a really simple situation: class

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread Ned Batchelder
On 3/2/18 10:36 AM, Paul Moore wrote: Or (real Python): 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 10,000 file descriptors open until the

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread Dietmar Schwertberger
On 2/28/2018 11:51 PM, ooom...@gmail.com wrote: This PEP proposes that valid python interpreters *must* synchronously destroy objects when the last reference to an object goes out of scope. This interpreter behaviour is currently permitted and exhibited by the reference implementation

Re: RFC: Proposal: Deterministic Object Destruction (Posting On Python-List Prohibited)

2018-03-03 Thread Chris Angelico
On Sun, Mar 4, 2018 at 3:19 AM, Richard Damon wrote: > On 3/3/18 9:03 AM, Ian Kelly wrote: >> >> On Fri, Mar 2, 2018 at 9:57 PM, Gregory Ewing >> wrote: >>> >>> Paul Rubin wrote: So you want the programmer to put more head

Re: RFC: Proposal: Deterministic Object Destruction (Posting On Python-List Prohibited)

2018-03-03 Thread Ian Kelly
On Sat, Mar 3, 2018 at 9:19 AM, Richard Damon wrote: > One idea does come to mind though, would it be reasonable, and somewhat > Pythonic, for a class to define member functions like __ref__ and __unref__ > (or perhaps some other name) that if defined, would be called

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread Michael Torrie
On 03/03/2018 09:02 AM, ooom...@gmail.com wrote: > I can assure you that RAII does what it says on the tin and is relied on in > many critical systems to release resources robustly ... given the > pre-requisite deterministic destruction. Sure but did you read what Paul Moore wrote? He said

Re: RFC: Proposal: Deterministic Object Destruction (Posting On Python-List Prohibited)

2018-03-03 Thread Richard Damon
On 3/3/18 9:03 AM, Ian Kelly wrote: On Fri, Mar 2, 2018 at 9:57 PM, Gregory Ewing wrote: Paul Rubin wrote: So you want the programmer to put more head scratching into figuring out which reference should be strong and which should be weak? Also, sometimes weak

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread ooomzay
On Friday, March 2, 2018 at 10:43:57 PM UTC, Steven D'Aprano wrote: > On Fri, 02 Mar 2018 07:09:19 -0800, ooomzay wrote: > [...] > >> If you're going to *require* the programmer to explicitly del the > >> reference: > >> > >> f = open("file") > >> text = f.read() > >> del f > > > >

Re: RFC: Proposal: Deterministic Object Destruction (Posting On Python-List Prohibited)

2018-03-03 Thread Ian Kelly
On Fri, Mar 2, 2018 at 9:57 PM, Gregory Ewing wrote: > Paul Rubin wrote: >> >> So you want the programmer to put more head scratching into figuring out >> which reference should be strong and which should be weak? > > > Also, sometimes weak references don't really

Re: RFC: Proposal: Deterministic Object Destruction (Posting On Python-List Prohibited)

2018-03-02 Thread Gregory Ewing
Paul Rubin wrote: So you want the programmer to put more head scratching into figuring out which reference should be strong and which should be weak? Also, sometimes weak references don't really solve the problem, e.g. if you have a graph where you can't identify any particular node as a

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-02 Thread Chris Angelico
On Sat, Mar 3, 2018 at 11:58 AM, Michael Torrie wrote: > On 03/02/2018 08:36 AM, Paul Moore wrote: >> On 2 March 2018 at 15:09, wrote: >>> We must be discussing a different RAII. That is the raison d'etre of RAII: >>> RAII directly addresses this problem

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-02 Thread Michael Torrie
On 03/02/2018 08:36 AM, Paul Moore wrote: > On 2 March 2018 at 15:09, wrote: >> We must be discussing a different RAII. That is the raison d'etre of RAII: >> RAII directly addresses this problem in an exception-safe way that does not >> burden the resource user at all. > >

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-02 Thread Steven D'Aprano
On Fri, 02 Mar 2018 07:09:19 -0800, ooomzay wrote: [...] >> If you're going to *require* the programmer to explicitly del the >> reference: >> >> f = open("file") >> text = f.read() >> del f > > But I am not! On the contrary RAII frees the programmer from even having > to remember to

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-02 Thread ooomzay
On Friday, March 2, 2018 at 2:43:09 PM UTC, Chris Angelico wrote: > On Sat, Mar 3, 2018 at 1:18 AM, ooomzay wrote: > > On Friday, March 2, 2018 at 8:16:22 AM UTC, Paul Rubin wrote:[snip] > >> controlling stuff like file handles > >> with scopes (like with "with") is fine. > > > > How does with

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-02 Thread Paul Moore
On 2 March 2018 at 15:09, wrote: > We must be discussing a different RAII. That is the raison d'etre of RAII: > RAII directly addresses this problem in an exception-safe way that does not > burden the resource user at all. RAII works in C++ (where it was initially invented)

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-02 Thread ooomzay
On Friday, March 2, 2018 at 4:35:41 AM UTC, Steven D'Aprano wrote: > On Thu, 01 Mar 2018 16:26:47 -0800, ooomzay wrote: > > >> >> When does the destination file get closed? > >> > > >> > When you execute:- > >> > > >> >del dst > >> > > >> > or:- > >> > > >> >dst = something_else > >> >

  1   2   >