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

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: 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 > > > <steve+comp.lang.pyt...@pearwood.info> wr

RFC: Proposal: Deterministic Object Destruction

2018-02-28 Thread ooomzay
Informal Background === Python's lack of Deterministic Object Destruction semantics strikes me as very unpythonic. This state of affairs spawns lengthy diatribes on __del__(), a variety of specialised and onerous resource management solutions and malignant carbuncles such as

Re: RFC: Proposal: Deterministic Object Destruction

2018-02-28 Thread ooomzay
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: > > Specification > > = > > > > When the last reference to an object goes out of scope the intepreter must > > synchrono

Re: RFC: Proposal: Deterministic Object Destruction

2018-02-28 Thread ooomzay
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: > > > > cla

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-01 Thread ooomzay
On Thursday, March 1, 2018 at 12:35:38 PM UTC, Richard Damon wrote: > [snip] > I disagree with the original complaint that these > are always 'errors', if you know you have garbage collection, the > allowance of cycles knowing they will still get cleaned up is a useful > simplification if you

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

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

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

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

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

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

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

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

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 assert

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

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

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:

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 compo

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 RAIIFileA

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 >

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("%

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

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

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

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 critic

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 exam

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 "

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-01 Thread ooomzay
On Thursday, March 1, 2018 at 11:59:26 PM UTC, Chris Angelico wrote: > On Fri, Mar 2, 2018 at 10:38 AM, ooomzay wrote: > > def raii_example(): > > > > src = RAIIFileAccess("src.txt", 'r') > > dst = RAIIFileAccess("dst.txt", 'w') > >

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-01 Thread ooomzay
On Thursday, March 1, 2018 at 12:15:57 AM UTC, Paul Rubin wrote: > RAII is similar to Python's "with" statement. So it sounds like OP > wants to replace one "malignant carbuncle" with another one. I would like to understand why you think RAII is not substantially more pythonic than "With".

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

2018-03-01 Thread ooomzay
On Thursday, March 1, 2018 at 11:51:50 PM UTC, Lawrence D’Oliveiro wrote: > On Friday, March 2, 2018 at 12:39:01 PM UTC+13, ooo...@gmail.com wrote: > > class RAIIFileAccess(): > > '''File Access-like Resource using [RAII] idiom''' > > > > ... > > > > def __del__(self): > >

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-01 Thread ooomzay
On Friday, March 2, 2018 at 12:14:53 AM UTC, Chris Angelico wrote: > On Fri, Mar 2, 2018 at 11:07 AM, ooomzay wrote: > > On Thursday, March 1, 2018 at 11:59:26 PM UTC, Chris Angelico wrote: > >> On Fri, Mar 2, 2018 at 10:38 AM, ooomzay wrote: > >> > def raii_ex

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

2018-03-02 Thread ooomzay
On Friday, March 2, 2018 at 1:59:02 AM UTC, Lawrence D’Oliveiro wrote: > On Friday, March 2, 2018 at 1:03:08 PM UTC+13, ooo...@gmail.com wrote: > > On Thursday, March 1, 2018 at 11:51:50 PM UTC, Lawrence D’Oliveiro wrote: > >> On Friday, March 2, 2018 at 12:39:01 PM UTC+13, ooo...@gmail.com wrote:

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

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-02 Thread ooomzay
On Friday, March 2, 2018 at 12:22:13 AM UTC, MRAB wrote: > On 2018-03-01 23:38, ooomzay wrote: [Snip] > > PEP343 requires two new methods: __enter__ & __exit__. > > RIAA requires no new methods. > > > > RIAA resources are invariant: If you have a reference t

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-02 Thread ooomzay
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 work for non-trivial/composite objects that represent/reference multiple resources or even a hierarchy of such objects where all the