Skip to content

Commit

Permalink
Try closing the file stream before writing
Browse files Browse the repository at this point in the history
Because Windows (and macOS?) might not support opening same temporary file twice.
  • Loading branch information
weiji14 committed Sep 9, 2020
1 parent aa3a521 commit fcd6cfe
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions pygmt/helpers/tempfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def __init__(self, prefix="pygmt-", suffix=".txt"):
args = dict(prefix=prefix, suffix=suffix, delete=False)
with NamedTemporaryFile(**args) as tmpfile:
self.name = tmpfile.name
self.close = tmpfile.close

def __enter__(self):
return self
Expand Down
1 change: 1 addition & 0 deletions pygmt/x2sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def tempfile_from_dftrack(track, suffix):
text file with a suffix (e.g. 'xyz').
"""
with GMTTempFile(suffix=suffix) as tmpfile:
tmpfile.close() # close the file stream
track.to_csv(
path_or_buf=tmpfile.name,
sep="\t",
Expand Down

0 comments on commit fcd6cfe

Please sign in to comment.