~ubuntu-branches/ubuntu/precise/pyzmq/precise

« back to all changes in this revision

Viewing changes to examples/heartbeat/heart.py

  • Committer: Bazaar Package Importer
  • Author(s): Piotr Ożarowski
  • Date: 2011-02-15 09:08:36 UTC
  • mfrom: (2.1.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20110215090836-phh4slym1g6muucn
Tags: 2.0.10.1-2
* Team upload.
* Upload to unstable
* Add Breaks: ${python:Breaks}

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
"""This launches an echoing rep socket device,
 
3
and runs a blocking numpy action. The rep socket should
 
4
remain responsive to pings during this time. Use heartbeater.py to
 
5
ping this heart, and see the responsiveness.
 
6
 
 
7
Authors
 
8
-------
 
9
* MinRK
 
10
"""
 
11
 
 
12
import time
 
13
import numpy
 
14
import zmq
 
15
from zmq import devices
 
16
 
 
17
ctx = zmq.Context()
 
18
 
 
19
dev = devices.ThreadDevice(zmq.FORWARDER, zmq.SUB, zmq.XREQ)
 
20
dev.setsockopt_in(zmq.SUBSCRIBE, "")
 
21
dev.connect_in('tcp://127.0.0.1:5555')
 
22
dev.connect_out('tcp://127.0.0.1:5556')
 
23
dev.start()
 
24
 
 
25
#wait for connections
 
26
time.sleep(1)
 
27
 
 
28
A = numpy.random.random((2**11,2**11))
 
29
print "starting blocking loop"
 
30
while True:
 
31
    tic = time.time()
 
32
    numpy.dot(A,A.transpose())
 
33
    print "blocked for %.3f s"%(time.time()-tic)
 
34