This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Glin
Recipients Glin
Date 2009-04-01.08:49:35
SpamBayes Score 2.4469597e-07
Marked as misclassified No
Message-id <1238575778.52.0.687578256719.issue5641@psf.upfronthosting.co.za>
In-reply-to
Content
Situation:
You have a while cycle. inside of it a try-except block and in this
try-except block calling a function. Inside of this function raises an
exception, with is caught in the try-except block.

What happens:
Local variables of the function are not freed. (OK, they are freed when
the program leaves a function inside of which is the while cycle, or
when another exception raises and is caught, but it's not helpful when
you have some server program based on infinite while loop or working
with a large amount of data).

Example:
Example program is attached.

Output of the example program:

While start
job() start
Creating 1
Catched AttributeError
While end
While start
job() start
Creating 2
job() end
Deleting 2
While end
While start
job() start
Creating 3
job() end
Deleting 3
While end
...

As you can see, a variable 'a' created in the first call (which throws
an exception) of the 'job' function will never get freed. 

Imagine that in 'job' function you create a large amount of data, or
worse you create a database connection, which will be opened forever.

Tested on Python 2.5.2 and 2.7(svn). On the contrary, Python 3.0 does
not have this issue (it frees variables of the 'job' function at the end
of except: block.)

As Python 2.X will be another long time with us, I think it should be
fixed to behave correctly (that is as in Python 3.)
History
Date User Action Args
2009-04-01 08:49:38Glinsetrecipients: + Glin
2009-04-01 08:49:38Glinsetmessageid: <1238575778.52.0.687578256719.issue5641@psf.upfronthosting.co.za>
2009-04-01 08:49:37Glinlinkissue5641 messages
2009-04-01 08:49:36Glincreate