本文整理汇总了Python中multiprocessing.pool.ThreadPool.starmap方法的典型用法代码示例。如果您正苦于以下问题:Python ThreadPool.starmap方法的具体用法?Python ThreadPool.starmap怎么用?Python ThreadPool.starmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.pool.ThreadPool
的用法示例。
在下文中一共展示了ThreadPool.starmap方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init
# 需要导入模块: from multiprocessing.pool import ThreadPool [as 别名]
# 或者: from multiprocessing.pool.ThreadPool import starmap [as 别名]
def init(self, export='csv', path='out'):
# 获取数据
# 校验完整性
# 记录出错的数据 / 或者
# ip = socket.gethostbyname(self.SINA_API_HOSTNAME)
stock_codes = self.get_all_stock_codes()
exists_codes = [code[:-4] for code in os.listdir(os.path.join(path, 'raw_data')) if code.endswith('.csv')]
stock_codes = set(stock_codes).difference(exists_codes)
pool = ThreadPool(500)
params = [(code, export, path) for code in stock_codes]
pool.starmap(self.out_stock_history, params)
示例2: init
# 需要导入模块: from multiprocessing.pool import ThreadPool [as 别名]
# 或者: from multiprocessing.pool.ThreadPool import starmap [as 别名]
def init(self, export='csv', path='out'):
# 获取数据
# 校验完整性
# 记录出错的数据 / 或者
# ip = socket.gethostbyname(self.SINA_API_HOSTNAME)
# self.SINA_API = self.SINA_API % ip
print(self.SINA_API)
stock_codes = self.get_all_stock_codes()
pool = ThreadPool(1)
params = [(code, export, path) for code in stock_codes]
pool.starmap(self.out_stock_history, params)
示例3: init
# 需要导入模块: from multiprocessing.pool import ThreadPool [as 别名]
# 或者: from multiprocessing.pool.ThreadPool import starmap [as 别名]
def init(self, export='csv', path='out'):
path = os.path.join(path, 'day')
self.result_path = os.path.join(path, 'data')
self.raw_path = os.path.join(path, 'raw_data')
if not os.path.exists(self.result_path):
os.makedirs(self.result_path)
if not os.path.exists(self.raw_path):
os.makedirs(self.raw_path)
stock_codes = self.get_all_stock_codes()
if os.path.exists(os.path.join(path, 'raw_data')):
exists_codes = [code[:-4] for code in os.listdir(os.path.join(path, 'raw_data')) if code.endswith('.csv')]
else:
exists_codes = set()
stock_codes = set(stock_codes).difference(exists_codes)
pool = ThreadPool(100)
params = [(code, export, path) for code in stock_codes]
pool.starmap(self.out_stock_history, params)
示例4: print
# 需要导入模块: from multiprocessing.pool import ThreadPool [as 别名]
# 或者: from multiprocessing.pool.ThreadPool import starmap [as 别名]
response = requests.post('https://www.ihg.com/gs-json/cn/zh/login',json=auth_json)
return json.loads(str(response.content, encoding='utf-8'))
except Exception as e:
print('发生{} 跳过账号 {}'.format(e.__traceback__,account))
return None
def spider_task(account_start,account_end,pwd):
for account in range(account_start,account_end):
response = _request(str(account),str(pwd))
if response:
_parseAccountDict(response)
if __name__ == '__main__':
pool = ThreadPool(5)
startAccount = int(input('输入 起始账号\n'))
endAccount = int(input('输入 结束账号\n'))
pwd = input('输入测试密码\n')
# 测试代码
# startAccount = 324577564
# endAccount = 324577570
# pwd = '0822'
accountSize = endAccount - startAccount
partLen = accountSize//5
args_map =[]
actor.start()
for i in range(5):
args_map.append((startAccount+i*partLen,startAccount+(i+1)*partLen,pwd))
pool.starmap(spider_task,args_map)
print('测试中 ...')
示例5: get_param
# 需要导入模块: from multiprocessing.pool import ThreadPool [as 别名]
# 或者: from multiprocessing.pool.ThreadPool import starmap [as 别名]
from multiprocessing.pool import ThreadPool
import time
def get_param():
paramList = []
for i in range(5000):
index = str(i)
thread_num = 'thread-' + str(i)
param = (index, thread_num)
paramList.append(param)
return paramList
def process_operator(index, thread_num):
print(thread_num, "say: i am", index)
if __name__ == '__main__':
s_time = time.time()
pool = ThreadPool(10)
paramList = get_param()
print(paramList)
pool.starmap(process_operator, paramList)
e_time = time.time()
total_time = e_time - s_time
print(total_time)