[py-dev] WindowsErrors when removing file (file in use)
Hi, This kind of relates to my last problem. With my new file-related test setup, I often get WindowsErrors when removing files, because they are still in use, because for some reason the file objects refuse to be closed or deleted, and are still wandering around when teardown_method is called. Again, I'm not sure whether this is something I'm doing wrong or a bug, but I've attached a test (simplified, with attempts at debugging), which fails with the error every second run (every other run the file exists at the start) on Python 2.5.2, py 0.9.1 or svn 57262, Windows XP. Matthew
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
participants (2)
-
Guido Wesdorp -
Matthew Edwards