diff --git a/CHANGELOG.md b/CHANGELOG.md index e519d71bb..d0599bddb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ # CHANGELOG + ## Unreleased ### Added ### Fixed +- close file descriptors after file operation is finished ### Changed ### Removed diff --git a/src/pyscipopt/scip.pyx b/src/pyscipopt/scip.pyx index 78ad7d24f..35dc637c5 100644 --- a/src/pyscipopt/scip.pyx +++ b/src/pyscipopt/scip.pyx @@ -10,7 +10,7 @@ cimport cython from cpython cimport Py_INCREF, Py_DECREF from cpython.pycapsule cimport PyCapsule_New, PyCapsule_IsValid, PyCapsule_GetPointer from libc.stdlib cimport malloc, free -from libc.stdio cimport fdopen +from libc.stdio cimport fdopen, fclose from collections.abc import Iterable from itertools import repeat @@ -4101,6 +4101,7 @@ cdef class Model: with open(filename, "w") as f: cfile = fdopen(f.fileno(), "w") PY_SCIP_CALL(SCIPprintBestSol(self._scip, cfile, write_zeros)) + fclose(cfile) def writeSol(self, Solution solution, filename="origprob.sol", write_zeros=False): """Write the given primal solution to a file. @@ -4115,6 +4116,7 @@ cdef class Model: with open(filename, "w") as f: cfile = fdopen(f.fileno(), "w") PY_SCIP_CALL(SCIPprintSol(self._scip, solution.sol, cfile, write_zeros)) + fclose(cfile) # perhaps this should not be included as it implements duplicated functionality # (as does it's namesake in SCIP) @@ -4460,6 +4462,7 @@ cdef class Model: with open(filename, "w") as f: cfile = fdopen(f.fileno(), "w") PY_SCIP_CALL(SCIPprintStatistics(self._scip, cfile)) + fclose(cfile) def getNLPs(self): """gets total number of LPs solved so far"""