Re: [Python-Dev] PEP 525, third round, better finalization

2016-09-03 Thread Greg Ewing
Nick Coghlan wrote: For synchronous code, that's a relatively easy burden to push back onto the programmer - assuming fair thread scheduling, a with statement can ensure reliably ensure prompt resource cleanup. That assurance goes out the window as soon as you explicitly pause code execution ins

Re: [Python-Dev] PEP 525, third round, better finalization

2016-09-03 Thread Yury Selivanov
Hi Oscar, I don't think PyPy is in breach of the language spec here. Python made a decision a long time ago to shun RAII-style implicit cleanup in favour if with-style explicit cleanup. The solution to this problem is to move resource management outside of the generator functions. This is true f

Re: [Python-Dev] PEP 525, third round, better finalization

2016-09-03 Thread Nick Coghlan
On 4 September 2016 at 04:38, Oscar Benjamin wrote: > On 3 September 2016 at 16:42, Nick Coghlan wrote: >> On 2 September 2016 at 19:13, Nathaniel Smith wrote: >>> This works OK on CPython because the reference-counting gc will call >>> handle.__del__() at the end of the scope (so on CPython it'

Re: [Python-Dev] PEP 525, third round, better finalization

2016-09-03 Thread Yury Selivanov
Hi Nathaniel, On 2016-09-02 2:13 AM, Nathaniel Smith wrote: On Thu, Sep 1, 2016 at 3:34 PM, Yury Selivanov wrote: Hi, I've spent quite a while thinking and experimenting with PEP 525 trying to figure out how to make asynchronous generators (AG) finalization reliable. I've tried to replace the

Re: [Python-Dev] PEP 525, third round, better finalization

2016-09-03 Thread Oscar Benjamin
On 3 September 2016 at 16:42, Nick Coghlan wrote: > On 2 September 2016 at 19:13, Nathaniel Smith wrote: >> This works OK on CPython because the reference-counting gc will call >> handle.__del__() at the end of the scope (so on CPython it's at level >> 2), but it famously causes huge problems whe

Re: [Python-Dev] PEP 525, third round, better finalization

2016-09-03 Thread Nick Coghlan
On 2 September 2016 at 19:13, Nathaniel Smith wrote: > This works OK on CPython because the reference-counting gc will call > handle.__del__() at the end of the scope (so on CPython it's at level > 2), but it famously causes huge problems when porting to PyPy with > it's much faster and more sophi

Re: [Python-Dev] PEP 525, third round, better finalization

2016-09-02 Thread Nathaniel Smith
On Thu, Sep 1, 2016 at 3:34 PM, Yury Selivanov wrote: > Hi, > > I've spent quite a while thinking and experimenting with PEP 525 trying to > figure out how to make asynchronous generators (AG) finalization reliable. > I've tried to replace the callback for GCed with a callback to intercept > first