When one sends the same request multiple times, which includes a form data file, and uses pdb to debug the application,
a warning is displayed that states that the application accesses a file that is already open.
If the client side application that uses postpy2 is not just a unit test but a long running application,
not closing the file can cause problems.
Hence, the file should be just opened once to read its content into memory and then be closed.
Therefore, one could use io.BytesIO which does not have to be closed.
io.BytesIO close method simply sets a boolean value self.closed to True (see the source code) :
def close(self):
self.closed = True
Thus, it makes the code safer to not cause any problems.
When one sends the same request multiple times, which includes a form data file, and uses
pdb
to debug the application, a warning is displayed that states that the application accesses a file that is already open.If the client side application that uses
postpy2
is not just a unit test but a long running application, not closing the file can cause problems. Hence, the file should be just opened once to read its content into memory and then be closed. Therefore, one could useio.BytesIO
which does not have to be closed.io.BytesIO
close method simply sets a boolean valueself.closed
toTrue
(see the source code) :Thus, it makes the code safer to not cause any problems.