-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython-client.py
More file actions
executable file
·41 lines (31 loc) · 882 Bytes
/
python-client.py
File metadata and controls
executable file
·41 lines (31 loc) · 882 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
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
import sys
import time
import logging
import random
import zmq
BASE_PORT = int(sys.argv[1])
WORKERS = int(sys.argv[2])
logging.basicConfig(
datefmt="%Y-%m-%d %H:%M:%S",
format="%(asctime)s %(name)s %(levelname)s: %(message)s",
level=logging.DEBUG
)
def main():
"""Main function."""
context = zmq.Context()
time.sleep(1)
socket = context.socket(zmq.REQ)
for offset in range(WORKERS):
socket.connect("tcp://localhost:{0}".format(BASE_PORT + offset))
while True:
data = random.sample(range(100), 10)
socket.send_json(data)
logging.info("Sent: {0}".format(data))
result_type, worker, result = socket.recv_json()
logging.info(
"Received: {0}: {1}: {2}".format(result_type, worker, result)
)
time.sleep(1)
if __name__ == '__main__':
main()