I have a xml file - kind of template to fill within the parameters and make a request (create some data).
I open this file with
tree = ET.parse(path_to_file)
and I make loop to get the xml from file, fill with the parameters and send a request. But after 2555 requests I get an error message:
IOError: [Errno 24] Too many open files: 'resources/cmr/skeletons/man/CreateLiveEvent.xml'
Is there a way to close file after ET.parse() opens it?
Thanks
Upgrade your 2.7 installation. This supposedly was fixed in issue #7334, and was included in 2.7.3. It does look like there is a bug in the way the cElementTree
implementation closes files however (e.g. it doesn't close them).
The alternative is to open the file yourself:
with open(path_to_file, 'rb') as xml_file:
tree = ET.parse(xml_file)
and leave it to the with
statement to close the file object. Open the file as binary; it is the job of the XML parser to handle line endings and encodings.
You could open the file yourself and close it:
source = open(path_to_file)
tree = ET.parse(source)
... do your work ...
source.close()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With