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

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

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 are a >> > closer >>

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 def

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 lifetime to allow RAII to work, but it doesn't j

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 op

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 o

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

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 case of a list element creat

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, but it doesn't just work with stack allocated o

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 > > objects are members of a c

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 y

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 significantly

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 pyth

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 functions like __ref__ and __unref

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 resource_i_care_abou

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 perhaps some other name) t

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 har

Re: cute interview problem

2018-03-03 Thread Ian Kelly
On Sat, Mar 3, 2018 at 3:26 PM, Richard Damon wrote: > On 2/28/18 3:51 PM, Ian Kelly wrote: >> >> On Wed, Feb 28, 2018 at 12:55 PM, wrote: >>> >>> On Tuesday, 27 February 2018 00:42:02 UTC+1, Paul Rubin wrote: Ron Aaron posted the below url on comp.lang.forth. It points to what I >>>

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 destru

Re: cute interview problem

2018-03-03 Thread Richard Damon
On 2/28/18 3:51 PM, Ian Kelly wrote: On Wed, Feb 28, 2018 at 12:55 PM, wrote: On Tuesday, 27 February 2018 00:42:02 UTC+1, Paul Rubin wrote: Ron Aaron posted the below url on comp.lang.forth. It points to what I thought was a cute problem, along with his solution in his Forth dialect 8th:

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 03/03/2018 09:02 AM, ooom...@gmail.com wrote: I can assu

Cheetah 3.1.0

2018-03-03 Thread Oleg Broytman
Hello! I'm pleased to announce version 3.1.0, the first stable release of branch 3.1 of CheetahTemplate3. What's new in CheetahTemplate3 == Contributors for this release is Mathias Stearn. Features: - Fix Cheetah to work with PyPy. Pull request by Mathias Stearn.

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, ooom...@gmail.com wrote: > > I can assure you

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 critical systems to releas

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 release resources robustly ..

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 read

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 every time a > name was bound

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

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 end

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

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 scratching into figuring out which reference should be stro

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 every time a > name was bound

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 RAI

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 references don't really solve th

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

"except" and "subclasscheck" changed between CPython2 and 3

2018-03-03 Thread 高岡陽太
Hello, I found a difference of behavior about `except` statement between CPython 2.7 and 3.x . `except EXC_CLASS:` calls `__subclasscheck__` in 2.7, but does not in 3.x . Let me show you an example. Now, define a class "ExceptionLike" (with metaclass "ExceptionLikeMeta") below. class ExceptionL

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 solve the > problem, e.g. if you

Re: read function of fuse

2018-03-03 Thread patatetom
after a few tests, it appears that the file is read in pieces: read[0] 131072 bytes from 0 flags: 0x8000 read[0] 131072 bytes from 131072 flags: 0x8000 read[0] 131072 bytes from 262144 flags: 0x8000 ... read[0] 8192 bytes from 917504 flags: 0x8000 read[0] 4096 bytes from 925696 flags: 0x8000 so t

read function of fuse

2018-03-03 Thread patatetom
hello, my xb360hd module allows me to browse a xtaf partition (xbox360) and extract files. a file can be large (and discontinuous), so the readFile function of the module returns a generator. from a console, I can "easily" copy a file with this piece of code: partition = xb360hd.Xtaf('/dev/sd