【发布时间】:2017-06-13 15:00:51
【问题描述】:
我只是在学习 Python,对多线程没有太多经验。我正在尝试通过 Requests session.post 方法发送一些 json。这在我需要遍历字典的许多 for 循环的底部的函数中调用。
有没有办法让它并行运行?
我还必须限制我的线程数,否则 post 调用会被阻塞,因为它们要彼此快速连接。帮助将不胜感激。
def doWork(session, List, RefHashList):
for itemRefHash in RefHashList:
for equipment in res['Response']['data']['items']:
if equipment['itemHash'] == itemRefHash:
if equipment['characterIndex'] != 0:
SendJsonViaSession(session, getCharacterIdFromIndex(res, equipment['characterIndex']), itemRefHash, equipment['quantity'])
【问题讨论】:
标签: python multithreading python-requests