test: python needs thread safety as well (#5992)

we have test cases which launch processes from threads, and they capture
output assuming this counter is thread-safe. at least according to my
understanding this operation in python requires a lock to be
thread-safe.
This commit is contained in:
Joonas Koivunen
2023-11-30 17:48:40 +02:00
committed by GitHub
parent 57ae9cd07f
commit eba3bfc57e

View File

@@ -138,17 +138,19 @@ def subprocess_capture(
_global_counter = 0
_global_counter_lock = threading.Lock()
def global_counter() -> int:
"""A really dumb global counter.
"""A really dumb but thread-safe global counter.
This is useful for giving output files a unique number, so if we run the
same command multiple times we can keep their output separate.
"""
global _global_counter
_global_counter += 1
return _global_counter
global _global_counter, _global_counter_lock
with _global_counter_lock:
_global_counter += 1
return _global_counter
def print_gc_result(row: Dict[str, Any]):