homepage

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.

classification
Title: SAX parse (ExpatParser) leaks file handle when given filename input
Type: resource usage Stage: resolved
Components: XML Versions: Python 2.7
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: berker.peksag, christian.heimes, mth, scoder, serhiy.storchaka, xtreak
Priority: normal Keywords:

Created on 2012年07月18日 14:17 by mth, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Messages (4)
msg165779 - (view) Author: Matt Hillsdon (mth) Date: 2012年07月18日 14:17
The following example uses make_parser / parse to read a trivial XML document by filename and then attempts to delete the file. On Win32 I can't unlink the file because the parse does not seem to close the file handle.
import os
import tempfile
from xml.sax import make_parser, ContentHandler
(handle, path) = tempfile.mkstemp()
os.write(handle, b"<foo/>")
os.close(handle)
parser = make_parser()
parser.parse(path)
# This unlink fails on win32. It succeeds if I comment out the call to parse.
os.unlink(path)
As I provide a filename rather than a file object, I would expect the parse call to both open and close it. I can't see a way to do the clean-up myself.
This issue exists in Python 2.7.3 but I could not reproduce it in 3.2.3.
Windows cmd transcript:
c:\Users\mth>Python2.7.3\python.exe fileleak.py
Traceback (most recent call last):
 File "fileleak.py", line 14, in <module>
 os.unlink(path)
WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'c:\\d\\tmpvyqg2c'
c:\Users\mth>Python3.2.3\python.exe fileleak.py
c:\Users\mth>
msg222974 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014年07月13日 21:20
@Matt I'm sorry that we haven't got back to you on this.
msg341008 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019年04月27日 19:09
Is this fixed with d81f9e24ea89c0aaded1e0d3f8d8076bbd58c19a ?
msg341015 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2019年04月27日 23:59
I just tested the snippet in msg165779 under Windows with Python 2.7.16. I didn't get WindowsError after I called os.unlink(path) and verified that path is removed from the file system.
I think we can close this issue as 'out of date'.
History
Date User Action Args
2022年04月11日 14:57:33adminsetgithub: 59593
2019年04月27日 23:59:41berker.peksagsetstatus: open -> closed

nosy: + berker.peksag
messages: + msg341015

resolution: out of date
stage: resolved
2019年04月27日 19:09:25xtreaksetnosy: + xtreak, serhiy.storchaka, scoder
messages: + msg341008
2019年04月26日 19:14:12BreamoreBoysetnosy: - BreamoreBoy
2014年07月13日 21:20:59BreamoreBoysetnosy: + christian.heimes, BreamoreBoy
messages: + msg222974
2013年02月05日 20:06:25serhiy.storchakalinkissue2840 superseder
2012年07月18日 14:17:29mthcreate

AltStyle によって変換されたページ (->オリジナル) /