本文整理匯總了Python中multiprocessing.dummy.Pool方法的典型用法代碼示例。如果您正苦於以下問題:Python dummy.Pool方法的具體用法?Python dummy.Pool怎麽用?Python dummy.Pool使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類multiprocessing.dummy
的用法示例。
在下文中一共展示了dummy.Pool方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run
# 需要導入模塊: from multiprocessing import dummy [as 別名]
# 或者: from multiprocessing.dummy import Pool [as 別名]
def run(self):
# http://www.kuaidaili.com/proxylist/1/
pool = Pool()
tt = pool.map(self.my_run, [page for page in xrange(1, 11)])
t_result = []
for x in tt:
t_result += x
# 填充結果集
result = []
info = dict()
info['url'] = self.url
info['type'] = self.type
info['tag'] = self.tag
result.append(info)
result.append(t_result)
self.result_queue.put(result)
示例2: __init__
# 需要導入模塊: from multiprocessing import dummy [as 別名]
# 或者: from multiprocessing.dummy import Pool [as 別名]
def __init__(self, feats_path, target, n_frames_per_video, batch_size, n_feat_maps, feat_map_side_dim, n_threads=10, annotation_dict=None):
random.seed(101)
np.random.seed(101)
self.__feats_pathes = feats_path
self.__n_frames_per_video = n_frames_per_video
self.__n_feat_maps = n_feat_maps
self.__feat_map_side_dim = feat_map_side_dim
self.__annotation_dict = annotation_dict
self.__batch_size = batch_size
self.__y = target
self.__is_busy = False
self.__batch_features = None
self.__batch_y = None
self.__n_threads_in_pool = n_threads
self.__pool = Pool(self.__n_threads_in_pool)
示例3: _start
# 需要導入模塊: from multiprocessing import dummy [as 別名]
# 或者: from multiprocessing.dummy import Pool [as 別名]
def _start(self):
try:
print '-'*60
print u'{}[-] 正在掃描地址: {}{} '.format(self.O,
socket.gethostbyname(self.target), self.W)
print '-'*60
#線程數
pool = ThreadPool(processes=100)
#get傳遞超時時間,用於捕捉ctrl+c
pool.map_async(self.run, self.ports).get(0xffff)
pool.close()
pool.join()
print '-'*60
print u'{}[-] 掃描完成耗時: {} 秒.{}'.format(self.O,
time()-self.time, self.W)
except Exception as e:
print e
except KeyboardInterrupt:
print self.R + u'\n[-] 用戶終止掃描...'
sys.exit(1)
示例4: get_node_id_feature_sparse
# 需要導入模塊: from multiprocessing import dummy [as 別名]
# 或者: from multiprocessing.dummy import Pool [as 別名]
def get_node_id_feature_sparse(self,X):
pool = ThreadPool(40)
#results = map(self.get_feaure, np.array(X.values))
results = pool.map(self.get_feaure, np.array(X.values))
results = list(results)
#print(results)
#results = np.array(results)
#print(results)
results = pd.DataFrame(results)
print(results.columns)
print("-------------")
results = pd.SparseDataFrame(pd.get_dummies(results)).astype("float")
print(results)
# columns = results.columns
# results = scipy.sparse.csr_matrix(results)
print(results.columns)
return results
示例5: reprojectToThisThreaded
# 需要導入模塊: from multiprocessing import dummy [as 別名]
# 或者: from multiprocessing.dummy import Pool [as 別名]
def reprojectToThisThreaded(self, sourceProjection, numThreads):
uvList = []
fx = float(self.imsize[0])
fy = float(self.imsize[1])
angleList = [self.angular_position((float(i)/fx,float(j)/fy)) for i in range(self.imsize[0]) for j in range(self.imsize[1])]
poolAngles = ThreadPool(numThreads)
image = poolAngles.map(sourceProjection.pixel_value, angleList)
poolAngles.close()
poolAngles.join()
idx = 0
for x in range(self.imsize[0]):
for y in range(self.imsize[1]):
pixel = image[idx]
if pixel is None:
print(x,y)
else:
self.image[y,x] = pixel
idx = idx + 1
示例6: __init__
# 需要導入模塊: from multiprocessing import dummy [as 別名]
# 或者: from multiprocessing.dummy import Pool [as 別名]
def __init__(self, args):
super(Slave, self).__init__()
self._pool=Pool(args.thread_num)
self._timeout=args.int_timeout
self._call_method=getattr(requests,args.int_method)
self._flags=args.int_flags.split(',,')
if args.int_headers!="":
self._headers=json.loads(input2json(args.int_headers))
else:
self._headers={}
if args.int_cookies!='':
cookiesl=args.int_cookies.split(',')
self._cookies={x.split(':')[0]:x.split(':')[1] for x in cookiesl}
else:
self._cookies={}
示例7: ancestral_reconstruction
# 需要導入模塊: from multiprocessing import dummy [as 別名]
# 或者: from multiprocessing.dummy import Pool [as 別名]
def ancestral_reconstruction(outgroup_genes):
""" Use Lazarus wrapper to run paml ancestral reconstruction """
print "Ancestral Reconstruction"
def run_lazarus(outgroup_gene):
coreGene, ingroup, outgroup = outgroup_gene
align = "%s/alignment/%s.nt_ali.fasta" % (coreGene, coreGene)
tree = "%s/tree/RAxML_bestTree.ml_%s.nt_ali" % (coreGene, coreGene)
model = "/opt/PepPrograms/paml4.8/dat/wag.dat"
outdir = os.path.abspath("%s/ancestral/" % coreGene)
call_with_log(LAZARUS_PATH + " --codeml --outputdir %s --verbose 9 \
--alignment %s --tree %s --model %s --asrv 4 --gapcorrect --getanc --ingroup %s\
--outgroup %s" % (outdir, align, tree, model, "[%s]" % (",".join(ingroup)),
"[%s]" % (outgroup)))
pool = ThreadPool(args.threads)
pool.map(run_lazarus, outgroup_genes)
pool.close()
pool.join()
示例8: test_multiprocessing
# 需要導入模塊: from multiprocessing import dummy [as 別名]
# 或者: from multiprocessing.dummy import Pool [as 別名]
def test_multiprocessing(self):
from multiprocessing.dummy import Pool
import random
import time
def square_slowly(x):
time.sleep(random.uniform(0.1, 0.2))
return x ** 2
pool = Pool(8)
start = time.time()
self.assertEqual([0, 1, 4, 9, 16, 25, 36, 49],
pool.map(square_slowly, range(8), chunksize=1))
duration = time.time() - start
self.assertGreater(duration, 0.1)
self.assertLess(duration, 0.25)
示例9: recursive
# 需要導入模塊: from multiprocessing import dummy [as 別名]
# 或者: from multiprocessing.dummy import Pool [as 別名]
def recursive(self, my_dir):
self.print_info("Recursive mode")
files_suid = []
files_sgid = []
files_list = []
for cpwd, dirs, files in walk(my_dir):
if cpwd.endswith("/"):
cwd = cpwd
else:
cwd = cpwd + "/"
for f in files:
files_list.append(cwd + f)
pool = Pool(8)
results = pool.map(self.is_suid_sgid, files_list)
pool.close()
pool.join()
for result in results:
if result[0]:
files_suid.append(result[0])
if result[1]:
files_sgid.append(result[1])
return [files_suid, files_sgid]
示例10: deploy_marvin
# 需要導入模塊: from multiprocessing import dummy [as 別名]
# 或者: from multiprocessing.dummy import Pool [as 別名]
def deploy_marvin(self):
if not self.get_marvin_json():
return False
print("Note: Found hypervisor type '" + self.get_hypervisor_type() + "'")
vms = []
for zone in self.get_zones():
for pod in self.get_pods(zone=zone):
for cluster in self.get_clusters(pod=pod):
vms += self.get_hosts(cluster=cluster)
vms += self.get_management_hosts(zone=zone)
vms += self.get_nsx_nodes()
thread_number = 10
if self.running_on_vm:
thread_number = 4
pool = ThreadPool(thread_number)
results = pool.map(self.deploy_host, vms)
print("Note: Deployment results: " + str(results))
pool.close()
pool.join()
return True
# Delete Marvin infra
示例11: delete_marvin
# 需要導入模塊: from multiprocessing import dummy [as 別名]
# 或者: from multiprocessing.dummy import Pool [as 別名]
def delete_marvin(self):
if not self.get_marvin_json():
return False
print("Note: Found hypervisor type '" + self.get_hypervisor_type() + "'")
hosts = self.get_hosts()
thread_number = 10
if self.running_on_vm:
thread_number = 4
pool = ThreadPool(thread_number)
results = pool.map(self.delete_host, hosts)
print("Note: Deployment results: " + str(results))
pool.close()
pool.join()
return True
# VM or not?
示例12: download_dataset
# 需要導入模塊: from multiprocessing import dummy [as 別名]
# 或者: from multiprocessing.dummy import Pool [as 別名]
def download_dataset(all_tasks, num_workers=4):
def urlretrieve_star(args):
return urlretrieve(*args)
pool = Pool(num_workers)
pool.map(urlretrieve_star, all_tasks)
pool.close()
pool.join()
示例13: do_upserts
# 需要導入模塊: from multiprocessing import dummy [as 別名]
# 或者: from multiprocessing.dummy import Pool [as 別名]
def do_upserts(self, account_list, concurrency, upsert_func):
"""Runs the upsert command for the accounts in `account_list`. Execution
happens in concurrent processes."""
success_ctr = multiprocessing.Value('i', 0, lock=True)
retry_ctr = multiprocessing.Value('i', 0, lock=True)
def _updater(acct):
upsert_func(addr=self.TEST_SERVER_ADDR, account=acct,
success_ctr=success_ctr, retry_ctr=retry_ctr)
pool = mpd.Pool(concurrency)
results = [
pool.apply_async(_updater, (acct,))
for acct in account_list for _ in range(concurrency)
]
_ = [res.get() for res in results]
pool.close()
示例14: generate_k_clusters
# 需要導入模塊: from multiprocessing import dummy [as 別名]
# 或者: from multiprocessing.dummy import Pool [as 別名]
def generate_k_clusters(self,folder):
pool = ThreadPool(cpu_count())
result = pool.map(self.read_image, folder)
pool.close()
pool.join()
self.cluster = [r[0] for r in result if r[0] != None]
self.data = [r[1] for r in result if r[1] != None]
self.end = [r[2] for r in result if r[2] != None]
示例15: __init__
# 需要導入模塊: from multiprocessing import dummy [as 別名]
# 或者: from multiprocessing.dummy import Pool [as 別名]
def __init__(self, dataset, feedin_shape, collate_fn=default_collate, threads=1, shuffle=False):
super(DataLoader, self).__init__()
self.dataset = dataset
self.threads = threads
self.collate_fn = collate_fn(feedin_shape)
# self.collate_fn = self.default_collate_fn
# shape related variables
self.data_shapes = feedin_shape['data']
self.label_shapes = feedin_shape['label']
self.batch_size = feedin_shape['batch_size']
# loader related variables
self.current = 0
self.total = len(self.dataset)
self.shuflle = shuffle
self.map_index = list(range(self.total))
# prepare for loading
self.get_batch = self.get_batch_single_thread
if self.threads > 1: # multi process read
from multiprocessing.dummy import Pool as ThreadPool
# self.pool = multiprocessing.Pool(self.threads)
self.pool = ThreadPool(self.threads)
self.get_batch = self.get_batch_multi_thread
self.reset()