[py-dev] WindowsErrors when removing file (file in use)

Guido Wesdorp johnny at johnnydebris.net
Sat Aug 16 10:22:08 CEST 2008


Matthew Edwards wrote:

...
>             logger = Logger(open(self.filename, 'wb'))
>             for packet in self.subjects:
>                 logger.recv(packet.data)
>             logger.file.close()
>   
If something goes wrong in the recv() call, the log file will not be 
closed with this code (something similar happens later with the reader). 
Could you try if things are better when you use try/finally to make sure 
that the file is closed:

fp = open(self.filename, 'wb')
try:
    logger = Logger(fp)
    for packet in self.subjects:
        logger.recv(packet.data)
finally:
    fp.close()

Hope that helps!

Cheers,

Guido



More information about the Pytest-dev mailing list