Python多处理(Pool)似乎会启动其他程序的重复进程
我不熟悉使用多处理和池,我认为当我的代码调用池时,它会启动另一个软件的多个进程,特别是R 我使用16个核心,这些核心不需要通信Python多处理(Pool)似乎会启动其他程序的重复进程,python,python-2.7,python-multiprocessing,python-pool,Python,Python 2.7,Python Multiprocessing,Python Pool,我不熟悉使用多处理和池,我认为当我的代码调用池时,它会启动另一个软件的多个进程,特别是R 我使用16个核心,这些核心不需要通信top显示所有Python进程都正确启动,但我注意到R似乎在累积运行实例。我的机器是Ubuntu16.04,每5分钟启动一次R,我注意到两个R实例的运行时间间隔为5分钟。换句话说,在这些情况下,我的计算机似乎启动了两个R实例。我可以使用killall R删除R实例。每个R实例使用了约99%的核心 起初,我认为这个问题与我的机器有关,但我注意到在我的Python脚本完成后的
top
显示所有Python进程都正确启动,但我注意到R似乎在累积运行实例。我的机器是Ubuntu16.04,每5分钟启动一次R,我注意到两个R实例的运行时间间隔为5分钟。换句话说,在这些情况下,我的计算机似乎启动了两个R实例。我可以使用killall R
删除R实例。每个R实例使用了约99%的核心
起初,我认为这个问题与我的机器有关,但我注意到在我的Python脚本完成后的某个时刻,行为停止了。(我不知道确切的时间,因为我没有在脚本运行的整个过程中监控它。)我用nohup
启动脚本,在nohup.out
中没有看到奇怪的输出。代码在Python 2.7上运行
完整代码位于此存储库的simulations.py:。我认为是相关的片段(如果需要更多细节,请告诉我):
一方面,我所有的代码都产生了它应该产生的东西。我想弄清楚到底发生了什么,这样我就不必担心在我不准备手动终止进程的时候,我的计算机会负担过重
run\u-trial\u from\u-tuple
做什么?它调用run\u-trial
函数,该函数完成脚本的主要工作。这是一个很长的函数,所以我不想把它放在问题的主体中。该函数和完整脚本可以在以下Github repo中找到:。我把回购链接也放在了帖子里。
def run_experiment(out_file, scales, repression_rates,
num_nodes=[40000], threshold=2, trials_per_setting=2500, num_procs=16):
"""Runs an experiment. Handles the main loops for running individual
trials, as well as the recording of data to a file. Returns nothing,
but writes to out_file.
Args:
out_file: file to write to
scales: an iterable of possible scaling parameters
repression_rates: an iterable of possible repression rates
num_nodes: how many nodes to put in each graph
threshold: the threshold to use for ProtestAgents
trials_per_setting: how many trials to run per
(scale X repression_rate) setting
num_procs: how many processes to spawn to run trials
"""
parameters = [(num, gamma, threshold, repression_rate)
for num in num_nodes for gamma in scales
for repression_rate in repression_rates
for _ in xrange(trials_per_setting)]
procs = Pool(num_procs)
# send work to pool, wrapped in a progress bar
data = list(tqdm.tqdm(procs.imap(run_trial_from_tuple, parameters),
total=len(parameters)))
# write output
head_line = ('num_nodes,gamma,threshold,repression_rate,initial_size,' +
'initial_density,initial_clustering,final_size,num_iters')
np.savetxt(out_file, data, delimiter=',', header=head_line, comments='')