Here are the examples of the python api requests.extend taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1 Examples
0
Source : client.py
with Apache License 2.0
from chalianwar
with Apache License 2.0
from chalianwar
def get_messages(q):
while True:
msg = q.get()
masterip = msg[0]
requests = json.loads(msg[1])
put_rand = requests[0]['random']
threads = requests[0]['threads']
ID = requests[0]['id']
master = (masterip, requests[0]['port'])
registry = requests[0]['registry']
wait = requests[0]['wait']
print master, ID, threads
processes = []
process_requests = []
delayed = []
for i in range(threads):
process_requests.append([])
delayed.append(0)
for r in requests[1:]:
i = 0
for j in range(len(delayed)):
if delayed[j] < delayed[i]:
i = j
if delayed[i] < r['delay']:
delayed[i] = r['delay'] + r['duration']
else:
delayed[i] += r['duration']
process_requests[i].append(r)
requests = [{'id': ID}]
startTime = time.time()
rq = Queue()
for i in range(threads):
first = registry.pop(0)
registry.append(first)
p = Process(target=send_requests, args=(registry, wait, put_rand, process_requests[i], startTime, rq))
p.start()
processes.append(p)
for i in range(threads):
requests.extend(rq.get())
for p in processes:
p.join()
print 'processes joined, sending response'
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
err = False
try:
sock.connect(master)
sock.sendall(json.dumps(requests))
except Exception as inst:
print inst
print "Error sending info, writing to file"
err = True
if err is True:
with open('error_output', 'w') as f:
f.write(json.dumps(requests))
sock.close()
print 'finished'
@app.route('/up', method="POST")