提交 299469ba 编写于 作者: L Li Hongzhang

address the importance of closing the SummaryRecord and illustrate how

上级 10cfc235
...@@ -61,12 +61,14 @@ def _dictlist(): ...@@ -61,12 +61,14 @@ def _dictlist():
class SummaryRecord: class SummaryRecord:
""" """
SummaryRecord is used to record the summary data and lineage data. SummaryRecord is used to record the summary data and lineage data.
The API will create a summary file and a lineage file lazily in a given directory and writes data to them.
It writes the data to files by executing the record method. In addition to record the data bubbled up from
the network by defining the summary operators, SummaryRecord also supports to record extra data which
can be added by calling add_value.
Note: Note:
The API will create a summary file and a lineage file lazily in a given directory and writes data to them. Make sure to close the SummaryRecord at the end, or the process will NOT exit.
It writes the data to files by executing the record method. In addition to record the data bubbled up from Please see the Example section below on how to properly close with two ways.
the network by defining the summary operators, SummaryRecord also supports to record extra data which
can be added by calling add_value. Finally, make sure to close the SummaryRecord object at the end.
Args: Args:
log_dir (str): The log_dir is a directory location to save the summary. log_dir (str): The log_dir is a directory location to save the summary.
...@@ -81,8 +83,15 @@ class SummaryRecord: ...@@ -81,8 +83,15 @@ class SummaryRecord:
RuntimeError: If the log_dir can not be resolved to a canonicalized absolute pathname. RuntimeError: If the log_dir can not be resolved to a canonicalized absolute pathname.
Examples: Examples:
>>> # use in with statement to auto close
>>> with SummaryRecord(log_dir="/opt/log", file_prefix="xxx_", file_suffix="_yyy") as summary_record: >>> with SummaryRecord(log_dir="/opt/log", file_prefix="xxx_", file_suffix="_yyy") as summary_record:
>>> pass >>> pass
>>>
>>> # use in try .. finally .. to ensure closing
>>> try:
>>> summary_record = SummaryRecord(log_dir="/opt/log")
>>> finally:
>>> summary_record.close()
""" """
def __init__(self, def __init__(self,
...@@ -310,8 +319,10 @@ class SummaryRecord: ...@@ -310,8 +319,10 @@ class SummaryRecord:
Flush all events and close summary records. Please use with statement to autoclose. Flush all events and close summary records. Please use with statement to autoclose.
Examples: Examples:
>>> with SummaryRecord(log_dir="/opt/log", file_prefix="xxx_", file_suffix="_yyy") as summary_record: >>> try:
>>> pass # summary_record autoclosed >>> summary_record = SummaryRecord(log_dir="/opt/log")
>>> finally:
>>> summary_record.close()
""" """
if not self._closed and self._event_writer: if not self._closed and self._event_writer:
# event writer flush and close # event writer flush and close
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册