MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / execute_only_once

Function execute_only_once

tensorpack/utils/utils.py:147–166  ·  view source on GitHub ↗

Each called in the code to this function is guaranteed to return True the first time and False afterwards. Returns: bool: whether this is the first time this function gets called from this line of code. Example: .. code-block:: python if execute_only_o

()

Source from the content-addressed store, hash-verified

145
146
147def execute_only_once():
148 """
149 Each called in the code to this function is guaranteed to return True the
150 first time and False afterwards.
151
152 Returns:
153 bool: whether this is the first time this function gets called from this line of code.
154
155 Example:
156 .. code-block:: python
157
158 if execute_only_once():
159 # do something only once
160 """
161 f = inspect.currentframe().f_back
162 ident = (f.f_code.co_filename, f.f_lineno)
163 if ident in _EXECUTE_HISTORY:
164 return False
165 _EXECUTE_HISTORY.add(ident)
166 return True
167
168
169def _pick_tqdm_interval(file):

Callers 2

__init__Method · 0.90
get_dataset_pathFunction · 0.85

Calls 1

addMethod · 0.45

Tested by

no test coverage detected