From d31e14f5932e7051dc51b4e6a5e9f7bcec375548 Mon Sep 17 00:00:00 2001 From: Li Hongzhang Date: Tue, 16 Jun 2020 10:43:05 +0800 Subject: [PATCH] fix having too many processes and no attribute of '_closed' 1. When initing SummaryRecord, if check failed, self._close is not set, which leads to 'SummaryRecord' object has no attribute '_closed' AttributeError later on. 2. There may be too many processes for handling summary adapting. See issue #I1K6K7 --- mindspore/train/summary/_event_writer.py | 2 +- mindspore/train/summary/summary_record.py | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/mindspore/train/summary/_event_writer.py b/mindspore/train/summary/_event_writer.py index ae347135f6..0a21dea04e 100644 --- a/mindspore/train/summary/_event_writer.py +++ b/mindspore/train/summary/_event_writer.py @@ -47,7 +47,7 @@ class EventWriter(Process): def run(self): - with Pool() as pool: + with Pool(min(cpu_count(), 32)) as pool: deq = deque() while True: while deq and deq[0].ready(): diff --git a/mindspore/train/summary/summary_record.py b/mindspore/train/summary/summary_record.py index b2bc872a1f..2c9b687db4 100644 --- a/mindspore/train/summary/summary_record.py +++ b/mindspore/train/summary/summary_record.py @@ -89,6 +89,8 @@ class SummaryRecord: file_suffix="_MS", network=None): + self._event_writer, self._closed = None, False + _check_str_by_regular(file_prefix) _check_str_by_regular(file_suffix) self.log_path = _make_directory(log_dir) @@ -113,7 +115,6 @@ class SummaryRecord: self.suffix = file_suffix self.network = network self.has_graph = False - self._closed = False # create the summary writer file self.event_file_name = get_event_file_name(self.prefix, self.suffix) @@ -122,8 +123,6 @@ class SummaryRecord: except Exception as ex: raise RuntimeError(ex) - self._event_writer = None - def _init_event_writer(self): """Init event writer and write metadata.""" event_writer = EventWriter(self.full_file_name, self.flush_time)