AttributeError:'Process'对象没有属性'set_cpu_affinity'

时间:2018-03-19 17:48:37

标签: multiprocessing joblib psutil

我正在运行joblib并遇到与here相同的问题,它只使用8个中的2个内核。我尝试按照here所述设置CPU亲和性。我正在使用psutil版本5.4.3。我仍然遇到这个错误:

AttributeError: 'Process' object has no attribute 'set_cpu_affinity'

这是我的剧本:

from datetime import datetime
from subprocess import call 
from joblib import Parallel, delayed
import multiprocessing
import psutil
import os

startTime = datetime.now()

pdb_name_list = []
for filename in os.listdir('/home/labusr/Documents/python_scripts/Spyder/Refinement'):
   if filename.endswith(".pdb"):     
       pdb_name_list.append(filename)

num_cores = multiprocessing.cpu_count()
p = psutil.Process(os.getpid())
p.set_cpu_affinity(range(num_cores))
print(p.get_cpu_affinity())

inputs = range(2) 

def strcuture_refine(file_name,i):
    print('Refining strcuture %s round %s......\n' %(file_name, i))
    call(['/home/labusr/rosetta/main/source/bin/rosetta_scripts.linuxgccrelease',
          '-in::file::s', '/home/labusr/Documents/python_scripts/Spyder/_Refinement/%s' %file_name,
          '-parser::protocol', '/home/labusr/Documents/A_asymm_refine.xml',
          '-parser::script_vars', 'denswt=35', 'rms=1.5', 'reso=4.3', 'map=/home/labusr/Documents/tubulin_exercise/masked_map_center.mrc', 
          'testmap=/home/labusr/Documents/tubulin_exercise/mmasked_map_top_centered_resampled.mrc',
          '-in:ignore_unrecognized_res',
          '-edensity::mapreso', '4.3',
          '-default_max_cycles', '200',
          '-edensity::cryoem_scatterers',
          '-beta',
          '-out::suffix', '_%s' %i,
          '-crystal_refine'])
    print('Time for refining %s round %s is: \n' %(file_name, i), datetime.now() - startTime)

for file_name in pdb_name_list:
    Parallel(n_jobs=num_cores)(delayed(strcuture_refine)(file_name,i) for i in inputs)

1 个答案:

答案 0 :(得分:0)

现在不推荐使用函数public class RootObject { public ResponseHeader responseHeader { get; set; } public Response response { get; set; } public Dictionary<string, Highlighting> highlighting { get; set; } } public class Highlighting { public List<string> _text_ { get; set; } }

相反,函数"highlighting"既充当获取器,又充当传递器。如果不提供参数,它将返回当前的亲和力,如果提供和参数将对其进行设置。

例如

"highlighting": {
   "File Name 1":{ "_text_":[ "text 1" ] },
   "File name 2":{ "_text_":[ "text 2" ] }
}