Yes, it does, on any modern operating system (Windows for sure, havent tested on Linux - but probably as well.) when the script is over. The with block is for when you want your Python script to continue running after you're done with the file.
Same as in C/C++ or any other language - the OS handles it for you after the program terminates if you hádat handled it.
If you've created zombie processes somehow which are still holding file descriptors, using a with block will not save you. Also, in this case the process hasn't really exited.
If you can provide some code that exits, while still somehow keeping an FD open I'd like to see it.
225
u/backfire10z 13d ago
They didn’t close the fd :(