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

Function worker

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

Source from the content-addressed store, hash-verified

61 return 1
62
63def worker(sensor_index, how_many):
64 global counter
65 # I have a barrier in here so the workers synchronize
66 # when they start counting, otherwise it's hard to get a race
67 # because the overhead of starting a thread is high.
68 BARRIER.wait()
69 for _ in range(how_many):
70 data = read_sensor(sensor_index)
71 # Note that the value passed to += must be a function call or other
72 # non-trivial expression in order to cause the CPython eval loop to
73 # check whether it should release the GIL. This is a side-effect of
74 # an optimization. See https://github.com/python/cpython/commit/4958f5d69dd2bf86866c43491caf72f774ddec97 for details.
75 counter += get_offset(data)
76
77
78print("Example 2")

Callers

nothing calls this directly

Calls 2

read_sensorFunction · 0.85
get_offsetFunction · 0.85

Tested by

no test coverage detected