File: ping.py

package info (click to toggle)
pyzmq 20.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,228 kB
  • sloc: python: 14,051; ansic: 941; cpp: 315; makefile: 179; sh: 32
file content (35 lines) | stat: -rw-r--r-- 708 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env python
"""For use with pong.py

This script simply pings a process started by pong.py or tspong.py, to 
demonstrate that zmq remains responsive while Python blocks.

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

import sys
import time
import numpy
import zmq

ctx = zmq.Context()

req = ctx.socket(zmq.REQ)
req.connect('tcp://127.0.0.1:10111')

#wait for connects
time.sleep(1)
n=0
while True:
    time.sleep(numpy.random.random())
    for i in range(4):
        n+=1
        msg = 'ping %i' % n
        tic = time.time()
        req.send_string(msg)
        resp = req.recv_string()
        print("%s: %.2f ms" % (msg, 1000*(time.time()-tic)))
        assert msg == resp