# -*- coding: utf-8 -*-
import datetime, os, sys
import time
import datetime
import socket
import grequests
import json
import asyncio
from aiohttp import ClientSession
tasks = []
tasksResult=[]
a = time.time()
async def request_run(i, semaphore):
async with semaphore:
async with ClientSession() as session:
parameter={"ServiceList":"INTERNET","Host":"www.baidu.com","DataBlockSize":64,"NumberOfRepet":5,"Timeout":1000}
tmp={}
tmp=parameter
tmp["Username"]=i
url='http://192.168.1.6:8190/public/test/testing/ping'
async with session.post(url, data=json.dumps(tmp)) as resp:
#response = await resp.read()
response = await resp.json()
print("req")
print(response)
reqResult={}
reqResult["Username"]=i
reqResult["reqresult"]=response
tasks.append(reqResult)
async def getResult_run(i, semaphore):
async with semaphore:
async with ClientSession() as session:
tmp={}
tmp["Username"]=i
url='http://192.168.1.6:8190/public/test/testing/ping/getpinginfo'
async with session.post(url, data=json.dumps(tmp)) as resp:
response = await resp.json()
print("result")
print(response)
reqResult={}
reqResult["Username"]=i
reqResult["result"]=response
tasksResult.append(reqResult)
async def run_req(userAccountList):
numlist=userAccountList.split(",");
semaphore = asyncio.Semaphore(100)
to_get = [request_run(i, semaphore) for i in numlist]
await asyncio.wait(to_get)
async def run_get(userAccountList):
numlist=userAccountList.split(",");
semaphore = asyncio.Semaphore(100)
to_getResult = [getResult_run(i, semaphore) for i in numlist]
await asyncio.wait(to_getResult)
if __name__ == "__main__":
while True:
userAccountList=''
if len(sys.argv) >1 :
userAccountList = sys.argv[1]
loop = asyncio.get_event_loop()
loop.run_until_complete(run_req(userAccountList))
#loop.run_until_complete(run_req(userAccountList))
loop.close()
print("req")
print(tasks)
print("result")
print(tasksResult)
b = time.time()
print(b-a)
break;