Skip to content

Commit

Permalink
Try to fix: cannot schedule new futures after interpreter shutdown (#657
Browse files Browse the repository at this point in the history
)

fixes #652 

https://docs.python.org/3.9/reference/datamodel.html#object.__del__
`It is not guaranteed that __del__() methods are called for objects that still exist when the interpreter exits.`
  • Loading branch information
lanpa committed Feb 6, 2022
1 parent 9fe8b74 commit db9b0fb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tensorboardX/record_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ def __init__(self, path):
raise ImportError("boto3 must be installed for S3 support.")
self.path = path
self.buffer = io.BytesIO()
self.closed = False

def __del__(self):
self.close()
if not self.closed:
self.close()

def bucket_and_path(self):
path = self.path
Expand All @@ -94,6 +96,7 @@ def flush(self):

def close(self):
self.flush()
self.closed = True


class S3RecordWriterFactory(object):
Expand Down
1 change: 1 addition & 0 deletions tests/test_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ def test_embedding_s3_mock(self):
label_img=all_images,
metadata_header=['digit', 'dataset'],
global_step=2)
w.close()

0 comments on commit db9b0fb

Please sign in to comment.