MCPcopy Create free account
hub / github.com/apache/tvm-ffi / worker

Function worker

tests/python/utils/filelock_worker.py:25–42  ·  view source on GitHub ↗

Worker function that tries to acquire lock and increment counter.

(worker_id: int, lock_path: str, counter_file: str)

Source from the content-addressed store, hash-verified

23
24
25def worker(worker_id: int, lock_path: str, counter_file: str) -> int:
26 """Worker function that tries to acquire lock and increment counter."""
27 try:
28 with FileLock(lock_path):
29 # Critical section - read, increment, write counter
30 with open(counter_file) as f: # noqa: PTH123
31 current_value = int(f.read().strip())
32
33 time.sleep(random.uniform(0.01, 0.1)) # Simulate some work
34
35 with open(counter_file, "w") as f: # noqa: PTH123
36 f.write(str(current_value + 1))
37
38 print(f"Worker {worker_id}: success")
39 return 0
40 except Exception as e:
41 print(f"Worker {worker_id}: error: {e}")
42 return 1
43
44
45if __name__ == "__main__":

Callers 1

filelock_worker.pyFile · 0.85

Calls 1

FileLockClass · 0.90

Tested by

no test coverage detected