MCPcopy Create free account
hub / github.com/bslatkin/effectivepython / locking_worker

Function locking_worker

example_code/item_069.py:135–141  ·  view source on GitHub ↗
(sensor_index, how_many)

Source from the content-addressed store, hash-verified

133counter_lock = Lock()
134
135def locking_worker(sensor_index, how_many):
136 global counter
137 BARRIER.wait()
138 for _ in range(how_many):
139 data = read_sensor(sensor_index)
140 with counter_lock: # Added
141 counter += get_offset(data)
142
143
144print("Example 7")

Callers

nothing calls this directly

Calls 2

read_sensorFunction · 0.85
get_offsetFunction · 0.85

Tested by

no test coverage detected