def __init__(self, log_name, experiments, cpu_limit=2**16):
"""
:param experiments: A list of pypuf.experiments.experiment.base.Experiment
:param log_name: A unique file path where to output should be logged.
:param cpu_limit: Maximum number of parallel processes that run experiments.
"""
# Store experiments list
self.experiments = experiments
# Store logger name
self.logger_name = log_name
# Setup parallel execution limit
self.cpu_limit = min(cpu_limit, multiprocessing.cpu_count())
self.semaphore = multiprocessing.BoundedSemaphore(self.cpu_limit)
python类BoundedSemaphore()的实例源码
validateupdaterini.py 文件源码
项目:PortableApps.com-DevelopmentToolkit
作者: 3D1T0R
项目源码
文件源码
阅读 29
收藏 0
点赞 0
评论 0
def main_threaded(iniconfig):
semaphore = BoundedSemaphore(CONCURRENCY_LIMIT)
tasks = []
for appid in iniconfig:
section = iniconfig[appid]
task = Thread(target=checker, args=(section, appid, semaphore))
tasks.append(task)
task.start()
try:
for t in tasks:
t.join()
except KeyboardInterrupt:
for t in tasks:
if hasattr(t, 'terminate'): # multiprocessing
t.terminate()
print 'Validation aborted.'
sys.exit(1)
def __init__(self):
# if any jobs marked in run state when scheduler starts
# replace their state with X to mark that they have been shutdown
db = DAL(config.uri, auto_import=True, migrate=False, folder=config.dbdir)
myset = db(db.jobs.state == STATE_RUN)
myset.update(state=STATE_STOPPED)
db.commit()
self.sem = BoundedSemaphore(config.np)
self.mutex = Lock()
# set time zone
try:
os.environ['TZ'] = config.time_zone
time.tzset()
except: pass
def test_bounded_semaphore(self):
sem = self.BoundedSemaphore(2)
self._test_semaphore(sem)
# Currently fails on OS/X
#if HAVE_GETVALUE:
# self.assertRaises(ValueError, sem.release)
# self.assertReturnsIfImplemented(2, get_value, sem)