Skip to content

Commit

Permalink
Prevent flush on closed NamedStream (#3507)
Browse files Browse the repository at this point in the history
* Prevent flush on closed NamedStream

* update changelog and docs

* revert versionchanged entry
  • Loading branch information
IAlibay authored Feb 3, 2022
1 parent 7fa06a6 commit 3c0875c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The rules for this file:
* 2.1.0

Fixes
* Prevents attempts to close an already closed NamedStream (Issue #3386)
* Added missing exe_err import in hole.py. Fixed a bug in HoleAnalysis where
kwarg was passed instead of object to generate path (Issue #3493, PR #3496)
* Fixes creation of vmd surfaces in hole2 when using non-contiguous frames
Expand Down
3 changes: 3 additions & 0 deletions package/MDAnalysis/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,9 @@ def close(self, force=False):
always closes the underlying stream.
"""
if self.closed:
return

if self.close_stream or force:
try:
return self.stream.close()
Expand Down
2 changes: 2 additions & 0 deletions testsuite/MDAnalysisTests/utils/test_streamio.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def test_closing_force(self):
assert_equal(ns.closed, False)
ns.close(force=True)
assert_equal(ns.closed, True)
# Issue 3386 - calling close again shouldn't raise an error
ns.close()

def test_StringIO_read(self):
obj = StringIO("".join(self.text))
Expand Down

0 comments on commit 3c0875c

Please sign in to comment.