diff options
-rw-r--r-- | event_log.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/event_log.py b/event_log.py index ef01394a..9ef52247 100644 --- a/event_log.py +++ b/event_log.py | |||
@@ -168,8 +168,10 @@ class EventLog: | |||
168 | f.write("\n") | 168 | f.write("\n") |
169 | 169 | ||
170 | 170 | ||
171 | # An integer id that is unique across this invocation of the program. | 171 | # An integer id that is unique across this invocation of the program, to be set |
172 | _EVENT_ID = multiprocessing.Value("i", 1) | 172 | # by the first Add event. We can't set it here since it results in leaked |
173 | # resources (see: https://issues.gerritcodereview.com/353656374). | ||
174 | _EVENT_ID = None | ||
173 | 175 | ||
174 | 176 | ||
175 | def _NextEventId(): | 177 | def _NextEventId(): |
@@ -178,6 +180,12 @@ def _NextEventId(): | |||
178 | Returns: | 180 | Returns: |
179 | A unique, to this invocation of the program, integer id. | 181 | A unique, to this invocation of the program, integer id. |
180 | """ | 182 | """ |
183 | global _EVENT_ID | ||
184 | if _EVENT_ID is None: | ||
185 | # There is a small chance of race condition - two parallel processes | ||
186 | # setting up _EVENT_ID. However, we expect TASK_COMMAND to happen before | ||
187 | # mp kicks in. | ||
188 | _EVENT_ID = multiprocessing.Value("i", 1) | ||
181 | with _EVENT_ID.get_lock(): | 189 | with _EVENT_ID.get_lock(): |
182 | val = _EVENT_ID.value | 190 | val = _EVENT_ID.value |
183 | _EVENT_ID.value += 1 | 191 | _EVENT_ID.value += 1 |