[issue18394] cgi.FieldStorage triggers ResourceWarning sometimes

Vajrasky Kok report at bugs.python.org
Mon Aug 12 13:22:20 CEST 2013


Vajrasky Kok added the comment:

It happens because if the length of data is more than 1000:

    def __write(self, line):
        """line is always bytes, not string"""
        if self.__file is not None:
            if self.__file.tell() + len(line) > 1000:
                self.file = self.make_file()
                data = self.__file.getvalue()
                self.file.write(data)
                self.__file = None
        ......

it will create a temporary file.

Attached the patch to close the temporary file in the destructor method.

About the 1000 number, should we put it in constant? Why 1000? This number is so random. For now, I just leave it as it is.

----------
keywords: +patch
nosy: +vajrasky
Added file: http://bugs.python.org/file31239/fix_resource_warning_in_test_cgi.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18394>
_______________________________________


More information about the Python-bugs-list mailing list