-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest.py
More file actions
32 lines (28 loc) · 935 Bytes
/
Copy pathrequest.py
File metadata and controls
32 lines (28 loc) · 935 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import requests
import grequests
import cPickle as pickle
import numpy as np
import util
import hparams as hp
import sys
import time
def request_action(url, state, reward):
"""
:param state: (img, flow, motor) tuple
"""
encoded = pickle.dumps((state, reward))
headers = {'content-type': 'text'}
response = requests.post(url + "/request_action", data=encoded, headers=headers)
return pickle.loads(response.content)
def batch_update(url, step_count):
headers = {'content-type': 'text'}
req = grequests.post(url + "/batch_update",
data=str(step_count), headers=headers)
req.send()
if __name__ == '__main__':
num_iters = int(sys.argv[1]) if len(sys.argv) > 1 else 100
print 'Sending {} batch requests to {}'.format(num_iters, hp.DQN_URL)
for i in range(num_iters):
print 'Requesting update', i
batch_update(hp.DQN_URL, i)
time.sleep(1./hp.FREQUENCY)