This PR fixes a file descriptor leak related bug in heat.py file. The calling of mkstemp() returns a random temp file name and a file descriptor. It becomes the responsibility of the user to close that file descriptor. Having too much of open file descriptors leads to an OSError [Errno 24].
PoC
from tempfile import mkstemp
import os
def heat():
_, tmp_file = mkstemp()
with open(tmp_file, "w") as f:
f.write("foo")
# do something
os.remove(tmp_file)
if __name__ == "__main__":
for i in range(100_000):
print(i+1)
heat()
Running the above program gives the output:
...
1019
1020
1021
Traceback (most recent call last):
File "/mnt/f/GitHub/test_pyheat.py", line 17, in <module>
File "/mnt/f/GitHub/test_pyheat.py", line 7, in heat
OSError: [Errno 24] Too many open files: '/tmp/tmp3h57izmy'
Overview
This PR fixes a file descriptor leak related bug in
heat.py
file. The calling ofmkstemp()
returns a random temp file name and a file descriptor. It becomes the responsibility of the user to close that file descriptor. Having too much of open file descriptors leads to anOSError [Errno 24]
.PoC
Running the above program gives the output: