Skip to content

Commit

Permalink
[fix #542] close file descriptors again
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmilten committed Nov 15, 2021
1 parent 972817f commit 5dbe696
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# CHANGELOG

## Unreleased
### Added
### Fixed
- close file descriptors after file operation is finished
### Changed
### Removed

Expand Down
5 changes: 4 additions & 1 deletion src/pyscipopt/scip.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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"""
Expand Down

0 comments on commit 5dbe696

Please sign in to comment.