本文整理汇总了Python中multiprocessing.dummy.Pool.close方法的典型用法代码示例。如果您正苦于以下问题:Python Pool.close方法的具体用法?Python Pool.close怎么用?Python Pool.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.dummy.Pool
的用法示例。
在下文中一共展示了Pool.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_and_rank_ip
# 需要导入模块: from multiprocessing.dummy import Pool [as 别名]
# 或者: from multiprocessing.dummy.Pool import close [as 别名]
def check_and_rank_ip(session):
def ping_jd(ip):
t = time.time()
try:
respond = requests.post('http://so.m.jd.com/ware/searchList.action',
data={'_format_': 'json', 'stock': 1, 'page': 1, 'keyword': '手机'},
proxies=ip.to_proxy(), timeout=5).content
json.loads(respond)
ip.rank = int(100 * (time.time() - t))
except Exception:
ip.rank = None
return ip
print datetime.now(), '开始判断ip活性'
from multiprocessing.dummy import Pool as ThreadPool
all_ip = session.query(IP).all()
pool = ThreadPool(100)
ips = pool.map(ping_jd, all_ip)
for ip in ips:
session.add(ip)
session.query(IP).filter(IP.rank == None).delete()
session.commit()
pool.close()
pool.join()
return session.query(IP).count()
示例2: main
# 需要导入模块: from multiprocessing.dummy import Pool [as 别名]
# 或者: from multiprocessing.dummy.Pool import close [as 别名]
def main():
dfbToken = raw_input('Enter your Dropbox Business API App token (Team Member File Access permission): ')
if args.verbose:
dumpArguments()
global fileQuota
fileQuota = args.quota * UNITS[args.units]
log("Creating Dropbox V2 API Client")
global dbxApiV2
dbxApiV2 = DbxApi(DbxApi.DBX_API_V2, dfbToken)
log("Collecting Member List...")
members = getDfbMembers(None)
# Filter out invited members as they can't consume any quota yet
activeMembers = [member for member in members if member.status != "invited"]
log("Got {} total team members ({} active, {} suspended, {} invited)"
.format(
len(members), len(activeMembers),
len(getMemberSublist(members, "suspended")),
len(getMemberSublist(members, "invited"))
))
log("Collecting file quota information - this may take a while...")
pool = ThreadPool(args.threads)
members = pool.map(getFileQuotaUsage, activeMembers)
pool.close()
pool.join()
# Write final output
log("Processing complete, writing output to {}".format(args.output.name))
dumpCsvFile(members)
示例3: run
# 需要导入模块: from multiprocessing.dummy import Pool [as 别名]
# 或者: from multiprocessing.dummy.Pool import close [as 别名]
def run():
t = [
('users', User().create),
('forums', Forum().create),
('threads', Thread().create),
('posts', Post().create),
("followers", User().follow),
("subscribptions", Thread().subscribe),
]
for entity, factory in t:
entities = [True for i in range(int(settings[entity]))]
num_tasks = len(entities)
pool = ThreadPool(int(settings['num_threads']))
try:
progress = range(5, 105, 5)
for i, _ in enumerate(pool.imap(factory, entities)):
perc = i * 100 / num_tasks
if perc % 5 == 0 and perc in progress:
log.print_out('Creating %s: %d%% done' % (entity, perc))
progress.remove(perc)
pool.close()
pool.join()
except Exception, e:
print e
pool.terminate()
sys.exit(1)
示例4: build_words_weight
# 需要导入模块: from multiprocessing.dummy import Pool [as 别名]
# 或者: from multiprocessing.dummy.Pool import close [as 别名]
def build_words_weight():
st = time.time()
bigvs = BigVs.objects.all()
def _build(b):
data = ArticlePostedResults.active_objects.filter(bigv__v_id=b.v_id, is_correct__in=(0, 1)).values('is_correct').annotate(count=Count('is_correct')).order_by('is_correct')
sum_c , w, c = 0, 0, 0
for d in data:
if d['is_correct'] == 1:
c = d['count']
sum_c += d['count']
if sum_c:
w = c * 1.0 / sum_c
c = w * 200
sum_c = 200
data = Judgement.objects.filter(article__bigv=b, judge__isnull=False).values('judge').annotate(count=Count('judge')).order_by('judge')
for d in data:
if d['judge'] == 'right':
c += d['count']
sum_c += d['count']
if sum_c:
w = int(round(c * 1.0 / sum_c * 100))
b.words_weight = w
b.save()
print b.name, c, sum_c, w
pool = Pool(8)
pool.map(_build, bigvs)
pool.close()
pool.join()
ed = time.time()
debug('build_words_weight', ed - st)
示例5: run
# 需要导入模块: from multiprocessing.dummy import Pool [as 别名]
# 或者: from multiprocessing.dummy.Pool import close [as 别名]
def run(threads):
urls = ['http://www.python.org',
'http://www.python.org/about/',
'http://www.onlamp.com/pub/a/python/2003/04/17/metaclasses.html',
'http://www.python.org/doc/',
'http://www.python.org/download/',
'http://www.python.org/getit/',
'http://www.python.org/community/',
'https://wiki.python.org/moin/',
'http://planet.python.org/',
'https://wiki.python.org/moin/LocalUserGroups',
'http://www.python.org/psf/',
'http://docs.python.org/devguide/',
'http://www.python.org/community/awards/'
]
results = []
scontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
requests = [urllib.request.Request(url=url,data=b'None',
headers={'User-Agent':' Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0'})
for url in urls]
pool = ThreadPool(threads)
results = list(pool.map(lambda x: urllib.request.urlopen(x, context=scontext), requests))
pool.close()
pool.join()
dataLen = [len(result.read().decode('utf-8')) for result in results]
print(threads, 'поток(ов), прочитано', sum(dataLen), 'байт')
示例6: collect_crystal
# 需要导入模块: from multiprocessing.dummy import Pool [as 别名]
# 或者: from multiprocessing.dummy.Pool import close [as 别名]
def collect_crystal():
print(datetime.now().strftime('%Y-%m-%d %H:%M:%S'), 'collect_crystal')
pool = ThreadPool(processes=5)
pool.map(check_collect, (json.loads(c.decode('utf-8')) for c in r_session.smembers('global:auto.collect.cookies')))
pool.close()
pool.join()
示例7: load
# 需要导入模块: from multiprocessing.dummy import Pool [as 别名]
# 或者: from multiprocessing.dummy.Pool import close [as 别名]
def load(cls, docs, ignore_errors=False):
"""Force load the provided docs to read from file system."""
if not docs:
return
pod = docs[0].pod
def load_func(doc):
"""Force the doc to read the source file."""
try:
# pylint: disable=pointless-statement
doc.has_serving_path() # Using doc fields forces file read.
except document_front_matter.BadFormatError:
if not ignore_errors:
raise
with pod.profile.timer('DocsLoader.load'):
if ThreadPool is None or len(docs) < cls.MIN_POOL_COUNT:
for doc in docs:
load_func(doc)
return
pool_size = min(cls.MAX_POOL_SIZE, len(docs) * cls.POOL_RATIO)
pool_size = int(round(pool_size))
thread_pool = ThreadPool(pool_size)
results = thread_pool.imap_unordered(load_func, docs)
# Loop results to make sure that the threads are all processed.
for _ in results:
pass
thread_pool.close()
thread_pool.join()
示例8: main
# 需要导入模块: from multiprocessing.dummy import Pool [as 别名]
# 或者: from multiprocessing.dummy.Pool import close [as 别名]
def main():
parser = argparse.ArgumentParser(usage='%(prog)s [options] SERVER_URL',
description=__doc__)
parser.add_argument(
'-t', '--threads',
help='Number of threads (simultaneous connections)',
dest='threads', default=1, type=int)
parser.add_argument('server', help='URL of server')
args = parser.parse_args()
server = args.server
if not server.startswith('http://'):
server = 'http://{}'.format(server)
icons = []
for font_id, font in fonts.items():
for char in font['characters']:
url = os.path.join(server, 'icon', font_id, '000', char)
icons.append((font_id, char, url))
icons.sort()
print('{} icons to test on {} ...'.format(len(icons), args.server))
if MAX_ICONS:
icons = icons[:MAX_ICONS]
pool = Pool(args.threads)
pool.map(check_icon, icons)
pool.close()
pool.join()
示例9: get_proxy
# 需要导入模块: from multiprocessing.dummy import Pool [as 别名]
# 或者: from multiprocessing.dummy.Pool import close [as 别名]
def get_proxy(self):
self._parse_proxy()
pool = ThreadPool(8)
pool.map(self._check_proxy, self.proxies)
pool.close()
pool.join()
return self.checked_proxies
示例10: e_cal
# 需要导入模块: from multiprocessing.dummy import Pool [as 别名]
# 或者: from multiprocessing.dummy.Pool import close [as 别名]
def e_cal(l, cores):
global LOOPS
'''
e calculator
this function will recive digits of float
and calculate and print status during working.
This function will return value of e.
'''
p = Pool()
getcontext().prec = l
e = Decimal(0)
i = 0
temp = 0
c = 0
while True:
fact = p.map(math.factorial, range(i, i+cores)) #parallel process factorial
e += sum(p.map(one_div, fact)) #processed factorial will total in here
i += cores
c += 1
LOOPS += 1
sys.stdout.write("\r%i loops passed." % (c) ) #Print Loop status
sys.stdout.flush()
#print i, "loops passed."
if e == temp:
break
temp = e
sys.stdout.write("\r%i loops passed.\n" % (c) )
print i
p.close()
p.join()
return e
示例11: multiRunuser
# 需要导入模块: from multiprocessing.dummy import Pool [as 别名]
# 或者: from multiprocessing.dummy.Pool import close [as 别名]
def multiRunuser():
pool = ThreadPool(cpu_count() * 8)
global ip_list
global results
results = pool.map_async(runuser, ip_list)
pool.close()
pool.join()
示例12: eval_dir
# 需要导入模块: from multiprocessing.dummy import Pool [as 别名]
# 或者: from multiprocessing.dummy.Pool import close [as 别名]
def eval_dir(fn, files_list):
pool = ThreadPool(WORKER_NUM)
results = pool.map(fn, files_list)
# close the pool and wait for the work to finish
pool.close()
pool.join()
return sum(results)
示例13: getAllSecrets
# 需要导入模块: from multiprocessing.dummy import Pool [as 别名]
# 或者: from multiprocessing.dummy.Pool import close [as 别名]
def getAllSecrets(version="", region=None, table="credential-store",
context=None, credential=None, session=None, **kwargs):
'''
fetch and decrypt all secrets
'''
if session is None:
session = get_session(**kwargs)
dynamodb = session.resource('dynamodb', region_name=region)
kms = session.client('kms', region_name=region)
secrets = listSecrets(region, table, **kwargs)
# Only return the secrets that match the pattern in `credential`
# This already works out of the box with the CLI get action,
# but that action doesn't support wildcards when using as library
if credential and WILDCARD_CHAR in credential:
names = set(expand_wildcard(credential,
[x["name"]
for x in secrets]))
else:
names = set(x["name"] for x in secrets)
pool = ThreadPool(min(len(names), THREAD_POOL_MAX_SIZE))
results = pool.map(
lambda credential: getSecret(credential, version, region, table, context, dynamodb, kms, **kwargs),
names)
pool.close()
pool.join()
return dict(zip(names, results))
示例14: get_proxys
# 需要导入模块: from multiprocessing.dummy import Pool [as 别名]
# 或者: from multiprocessing.dummy.Pool import close [as 别名]
def get_proxys(file_name, thread_num=5):
"""这里的文件内容可以是从cn-proxy.com复制过来的数据"""
proxys = []
ip_reg = re.compile(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', re.I)
try:
with open(file_name, 'r') as fd_proxy:
for line in fd_proxy:
if line and line.strip():
print 'line',line.strip()
if ip_reg.match(line.strip()):
ip, port = line.strip().split()[0], line.strip().split()[1]
proxy = '%s:%s' %(ip, port)
print 'proxy',proxy
# if test_connection(proxy):
if proxy:
proxys.append(proxy)
pool = ThreadPool(thread_num)
results = pool.map(test_connection,proxys)
pool.close()
pool.join()
proxys = list(set(results))
proxys = sorted(proxys,key=lambda x:x.split(".")[0])
except Exception,e:
print 'error',e
示例15: make_unaligned_fasta
# 需要导入模块: from multiprocessing.dummy import Pool [as 别名]
# 或者: from multiprocessing.dummy.Pool import close [as 别名]
def make_unaligned_fasta(dnaDirectory, groupsDict):
""" Reads through files in provided directory to find gene sequences that
match the proteins in the groups dictionary"""
print "Collecting core genes"
def make_fasta(group):
proteins = groupsDict[group]
out = open('proteinAlignments/' + group + '.fasta', 'w')
records = []
seqIDs = []
for protein in proteins:
seqID = protein.split('|')[0]
seqIDs.append(seqID)
protein = protein.split('|')[1]
records.append(seqRecordDict[protein])
SeqIO.write(records, out, 'fasta')
return seqIDs
try:
os.makedirs("proteinAlignments")
except OSError:
if not os.path.isdir("proteinAlignments"):
raise
files = listdir_fullpath(dnaDirectory)
seqRecordDict = {}
seqIDs = []
for f in files:
handle = open(f, 'r')
for record in SeqIO.parse(handle, 'fasta'):
seqRecordDict[record.id] = record
pool = ThreadPool(args.threads)
seqIDs = pool.map(make_fasta, groupsDict.keys())
pool.close()
pool.join()
return seqIDs[0]