Re: [Tutor] finally without try or except

2012-07-31 Thread Don Jennings
On Jul 31, 2012, at 12:26 PM, tutor-requ...@python.org wrote: > Message: 2 > Date: Tue, 31 Jul 2012 10:44:29 -0400 > From: Tino Dai > To: "Steven D'Aprano" > Cc: "tutor@python.org" > Subject: Re: [Tutor] finally without try or except > Message-ID

Re: [Tutor] finally without try or except

2012-07-31 Thread Hugo Arts
On Tue, Jul 31, 2012 at 5:23 PM, Prasad, Ramit wrote: > [snip] > > > >> This will be the most robust as it will > > >> also work for cases where the program is terminated without the use of > > >> the keyboard (i.e. kill -9, task manager, computer reboot, etc.) but > > > > That unfortunately is n

Re: [Tutor] finally without try or except

2012-07-31 Thread Prasad, Ramit
[snip] > >> This will be the most robust as it will > >> also work for cases where the program is terminated without the use of > >> the keyboard (i.e. kill -9, task manager, computer reboot, etc.) but > > That unfortunately is not so. kill -9 does *not* send a signal or raise an > exception. It

Re: [Tutor] finally without try or except

2012-07-31 Thread Tino Dai
On Mon, Jul 30, 2012 at 9:01 PM, Steven D'Aprano wrote: > If you want to be robust, it is best not to try to beat the database. That > means you should write to the database as soon as you can, as often as you > need to, and let the database do what it does best: reliable transaction > storage. An

Re: [Tutor] finally without try or except

2012-07-30 Thread Steven D'Aprano
Tino Dai wrote: I just remember that there was a performance hit or something for doing that. Does that sound familiar to anyone? Yes, and no. Creating a try block in Python is lightweight and fast. It is about as fast as the "pass" statement, that is, pretty damn fast and more or less faste

Re: [Tutor] finally without try or except

2012-07-30 Thread Steven D'Aprano
Tino Dai wrote: Yes, but that would involve surrounding the entire method with a try except finally block. I was told by the Python-Guru-In Residence that shouldn't emulate Java code in Python, and that was generally bad programming practice (no flame war intended) And that is correct. It is *

Re: [Tutor] finally without try or except

2012-07-30 Thread eryksun
On Mon, Jul 30, 2012 at 3:10 PM, Tino Dai wrote: > On Mon, Jul 30, 2012 at 1:52 PM, Mark Lawrence > wrote: > >> Sorry I'm not completely sure what you're asking for but will this help >> http://docs.python.org/library/atexit.html ? >> > I think this might be what I'm looking for. But for about 2

Re: [Tutor] finally without try or except

2012-07-30 Thread Tino Dai
On Mon, Jul 30, 2012 at 3:35 PM, Brett Ritter wrote: > On Mon, Jul 30, 2012 at 12:20 PM, Tino Dai wrote: > > Yes, but that would involve surrounding the entire method with a try > except > > finally block. I was > > told by the Python-Guru-In Residence that shouldn't emulate Java code in > > Pyt

Re: [Tutor] finally without try or except

2012-07-30 Thread Brett Ritter
On Mon, Jul 30, 2012 at 12:20 PM, Tino Dai wrote: > Yes, but that would involve surrounding the entire method with a try except > finally block. I was > told by the Python-Guru-In Residence that shouldn't emulate Java code in > Python, and that was > generally bad programming practice (no flame wa

Re: [Tutor] finally without try or except

2012-07-30 Thread Steve Willoughby
On 30-Jul-12 10:52, Mark Lawrence wrote: On 30/07/2012 17:56, Tino Dai wrote: Is there anyway to execute a block of code at the end of a program in 2.6 regardless of what happened before eg exiting normally or died because of an exception? Sorry I'm not completely sure what you're askin

Re: [Tutor] finally without try or except

2012-07-30 Thread Alan Gauld
On 30/07/12 17:56, Tino Dai wrote: Is there anyway to execute a block of code at the end of a program in 2.6 regardless of what happened before eg exiting normally or died because of an exception? Yes, try/finally. That's what it's there for. I was thinking about maybe a free standing

Re: [Tutor] finally without try or except

2012-07-30 Thread Tino Dai
On Mon, Jul 30, 2012 at 1:44 PM, Prasad, Ramit wrote: > > Actually, what I'm doing is keeping a pending item log in memory as an > array > > and then saving it to the DB at the end of the program, but what happens > if > > the user hits ctrl-c, then the pending items array is lost. That's the > us

Re: [Tutor] finally without try or except

2012-07-30 Thread Tino Dai
On Mon, Jul 30, 2012 at 2:44 PM, Albert-Jan Roskam wrote: > *From:* Tino Dai > > *To:* nz*tutor pythonzzz > *Sent:* Monday, July 30, 2012 6:56 PM > *Subject:* [Tutor] finally without try or except > > Hi! > > Is there anyway to execute a block of code at th

Re: [Tutor] finally without try or except

2012-07-30 Thread Tino Dai
On Mon, Jul 30, 2012 at 1:52 PM, Mark Lawrence wrote: > On 30/07/2012 17:56, Tino Dai wrote: > >> Hi! >> >> Is there anyway to execute a block of code at the end of a program >> in >> 2.6 regardless of what happened before eg exiting normally or died because >> of an exception? >> I was thin

Re: [Tutor] finally without try or except

2012-07-30 Thread Albert-Jan Roskam
From: Tino Dai To: nz*tutor pythonzzz >Sent: Monday, July 30, 2012 6:56 PM >Subject: [Tutor] finally without try or except > > >Hi! > > >     Is there anyway to execute a block of code at the end of a program in 2.6 >regardless of what happened before eg exiting

Re: [Tutor] finally without try or except

2012-07-30 Thread Mark Lawrence
On 30/07/2012 17:56, Tino Dai wrote: Hi! Is there anyway to execute a block of code at the end of a program in 2.6 regardless of what happened before eg exiting normally or died because of an exception? I was thinking about maybe a free standing finally code block or a decorator. Any hint

Re: [Tutor] finally without try or except

2012-07-30 Thread Prasad, Ramit
> Actually, what I'm doing is keeping a pending item log in memory as an array > and then saving it to the DB at the end of the program, but what happens if > the user hits ctrl-c, then the pending items array is lost. That's the use > case that I'm looking for a solution to. http://docs.python.or

Re: [Tutor] finally without try or except

2012-07-30 Thread Tino Dai
On Mon, Jul 30, 2012 at 1:16 PM, Marc Tompkins wrote: > On Mon, Jul 30, 2012 at 9:56 AM, Tino Dai wrote: > >> Hi! >> >> Is there anyway to execute a block of code at the end of a program >> in 2.6 regardless of what happened before eg exiting normally or died >> because of an exception? >> I

Re: [Tutor] finally without try or except

2012-07-30 Thread Marc Tompkins
On Mon, Jul 30, 2012 at 9:56 AM, Tino Dai wrote: > Hi! > > Is there anyway to execute a block of code at the end of a program in > 2.6 regardless of what happened before eg exiting normally or died because > of an exception? > I was thinking about maybe a free standing finally code block or

[Tutor] finally without try or except

2012-07-30 Thread Tino Dai
Hi! Is there anyway to execute a block of code at the end of a program in 2.6 regardless of what happened before eg exiting normally or died because of an exception? I was thinking about maybe a free standing finally code block or a decorator. Any hints? Tino