Re: yield in try/finally case

2016-03-03 Thread Oscar Benjamin
On 3 March 2016 at 15:12, Random832 wrote: > On Thu, Mar 3, 2016, at 08:47, Peter Otten wrote: >> This is because the last generator uf = upperfile(...) is not garbage- >> collected and wasn't explicitly closed either. > > But the program hasn't ended yet when you run your assertion. > > import sy

Re: yield in try/finally case

2016-03-03 Thread Peter Otten
Random832 wrote: > On Thu, Mar 3, 2016, at 08:47, Peter Otten wrote: >> This is because the last generator uf = upperfile(...) is not garbage- >> collected and wasn't explicitly closed either. > > But the program hasn't ended yet when you run your assertion. If your expectations are in line with

Re: yield in try/finally case

2016-03-03 Thread Steven D'Aprano
On Fri, 4 Mar 2016 02:00 am, Random832 wrote: > On Thu, Mar 3, 2016, at 06:52, 刘琦帆 wrote: >> I have just saw PEP 255, and it says that >> >> "A yield statement is not allowed in the try clause of a try/finally >> construct. The difficulty is that there's no guarantee the generator >> will ever b

Re: yield in try/finally case

2016-03-03 Thread Random832
On Thu, Mar 3, 2016, at 08:47, Peter Otten wrote: > This is because the last generator uf = upperfile(...) is not garbage- > collected and wasn't explicitly closed either. But the program hasn't ended yet when you run your assertion. import sys _open = open files = [] def myclose(self): pri

Re: yield in try/finally case

2016-03-03 Thread Random832
On Thu, Mar 3, 2016, at 06:52, 刘琦帆 wrote: > I have just saw PEP 255, and it says that > > "A yield statement is not allowed in the try clause of a try/finally > construct. The difficulty is that there's no guarantee the generator > will ever be resumed, hence no guarantee that the finally block

Re: yield in try/finally case

2016-03-03 Thread Peter Otten
刘琦帆 wrote: > 在 2016年3月3日星期四 UTC+8下午8:14:29,Oscar Benjamin写道: >> On 3 March 2016 at 11:52, 刘琦帆 wrote: >> > >> > "A yield statement is not allowed in the try clause of a try/finally >> > construct. The difficulty is that there's no guarantee the generator >> > will ever be resumed, hence no guaran

Re: yield in try/finally case

2016-03-03 Thread 刘琦帆
在 2016年3月3日星期四 UTC+8下午8:14:29,Oscar Benjamin写道: > On 3 March 2016 at 11:52, 刘琦帆 wrote: > > > > "A yield statement is not allowed in the try clause of a try/finally > > construct. The difficulty is that there's no guarantee the generator will > > ever be resumed, hence no guarantee that the fina

Re: yield in try/finally case

2016-03-03 Thread Oscar Benjamin
On 3 March 2016 at 11:52, 刘琦帆 wrote: > > "A yield statement is not allowed in the try clause of a try/finally > construct. The difficulty is that there's no guarantee the generator will > ever be resumed, hence no guarantee that the finally block will ever get > executed; that's too much a vio

yield in try/finally case

2016-03-03 Thread 刘琦帆
I have just saw PEP 255, and it says that "A yield statement is not allowed in the try clause of a try/finally construct. The difficulty is that there's no guarantee the generator will ever be resumed, hence no guarantee that the finally block will ever get executed; that's too much a violati