does python have useless destructors?

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Fri Jun 11 11:52:36 EDT 2004


On Fri, 11 Jun 2004 08:44:39 -0700, Tim Bradshaw wrote:

>> myfile = open("myfilepath", "w")
>> 
>> try:
>>     myfile.write(reallybigbuffer)
>> finally:
>>     myfile.close()
> 
> I don't think this is save.  Is it certain that there can be no
> problem between the open and the try?  The expansion of Lisp macros
> which do this typically look like:
> 
> myfile = None
> 
> try:
>     myfile = open(...)

What is the difference? If there are no asynchronous exceptions, both
are safe (nothing can happen in-between). And if there are asynchronous
exceptions, both are unsafe (the exception might come after open returned
but before its result is stored).

Glasgow Haskell has functions which temporarily block asynchronous
exceptions for cases like this.

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak at knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/




More information about the Python-list mailing list