mirror of
https://github.com/neondatabase/neon.git
synced 2025-12-23 06:09:59 +00:00
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:
@@ -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]):
|
||||
|
||||
Reference in New Issue
Block a user