summaryrefslogtreecommitdiff
path: root/examples/heartbeat/pong.py
blob: 524f394711b3c55cbf471e8c524d3eb6a42b57d8 (plain)
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
#!/usr/bin/env python
"""This launches an echoing rep socket device using 
zmq.devices.ThreadDevice, and runs a blocking numpy action. 
The rep socket should remain responsive to pings during this time.

Use ping.py to see how responsive it is.

Authors
-------
* MinRK
"""
from __future__ import print_function

import time
import numpy
import zmq
from zmq import devices

ctx = zmq.Context()

dev = devices.ThreadDevice(zmq.FORWARDER, zmq.REP, -1)
dev.bind_in('tcp://127.0.0.1:10111')
dev.setsockopt_in(zmq.IDENTITY, b"whoda")
dev.start()

#wait for connections
time.sleep(1)

A = numpy.random.random((2**11,2**12))
print("starting blocking loop")
while True:
    tic = time.time()
    numpy.dot(A,A.transpose())
    print("blocked for %.3f s"%(time.time()-tic))