def __init__(self, j=os.cpu_count(), max_utilization=100):
"""
Initialize a parallel loop object.
:param j: The maximum number of parallel jobs.
:param max_utilization: The maximum CPU utilization. Above this no more new jobs
will be started.
"""
self._j = j
self._max_utilization = max_utilization
# This gets initialized to 0, may be set to 1 anytime, but must not be reset to 0 ever;
# thus, no locking is needed when accessing
self._break = multiprocessing.sharedctypes.Value('i', 0, lock=False)
self._lock = multiprocessing.Condition()
self._slots = multiprocessing.sharedctypes.Array('i', j, lock=False)
psutil.cpu_percent(None)
# Beware! this is running in a new process now. state is shared with fork,
# but only changes to shared objects will be visible in parent.
评论列表
文章目录