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
()
| 145 | |
| 146 | |
| 147 | def 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 | |
| 169 | def _pick_tqdm_interval(file): |
no test coverage detected