现在的逻辑是:
多进程请求。直到我们得到所需的响应 将事件设置为停止和终止进程
但是,在终止之前执行的请求仍然完成了它们的工作,这是我负担不起的。我需要他们在我的病情结束后立即停止治疗。我甚至可以在一秒钟内为脚本杀死网络适配器,如果需要的话。我只需要走上正轨
这是在Windows上,运行python2.7,多处理和请求libs
有没有办法在请求中间停止请求模块的连接(需要停止所有在不同进程上运行的进程)
例如:
def worker(found_event):
print 'process started'
randDelay = random.randint(4, 10)
response = requests.post('http://httpbin.org/delay'+str(randDelay))
print response.status_code
found_event.set()
if __name__ == "__main__":
found_event = Event()
pool = [Process(target=worker, args=(found_event,)) for i in range(10)]
for p in pool:
p.start()
found_event.wait()
for p in pool:
p.terminate()
for p in pool:
p.join()
有时返回:
process started
process started
process started
process started
process started
process started
process started
process started
process started
process started
404
有时:
process started
process started
process started
process started
process started
process started
process started
process started
process started
process started
404404
目前没有回答
相关问题 更多 >
编程相关推荐