Skip to content

Commit

Permalink
Merge pull request #118 from mrshu/mrshu/summary_writer-fix
Browse files Browse the repository at this point in the history
fix #108
  • Loading branch information
lanpa committed Apr 12, 2018
2 parents 3882334 + 303154a commit 76b8a58
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions tensorboardX/event_file_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def flush(self):
def close(self):
'''Call self.flush().'''
return_value = self.flush()
self._py_recordio_writer.close()
return return_value


Expand Down
3 changes: 3 additions & 0 deletions tensorboardX/record_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def write(self, event_str):
w(struct.pack('I', masked_crc32c(event_str)))
self._writer.flush()

def close(self):
self._writer.close()


def masked_crc32c(data):
x = u32(crc32c(data))
Expand Down
14 changes: 14 additions & 0 deletions tests/test_summary_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,17 @@ def test_summary_writer_ctx():
with SummaryWriter() as writer:
writer.add_scalar('test', 1)
assert writer.file_writer is None


def test_summary_writer_close():
# Opening and closing SummaryWriter a lot should not run into
# OSError: [Errno 24] Too many open files
passed = True
try:
for i in range(10000):
writer = SummaryWriter()
writer.close()
except OSError:
passed = False

assert passed

0 comments on commit 76b8a58

Please sign in to comment.