~ubuntu-branches/ubuntu/wily/pyzmq/wily

« back to all changes in this revision

Viewing changes to perf/remote_thr.py

  • Committer: Package Import Robot
  • Author(s): Julian Taylor
  • Date: 2013-02-24 19:23:15 UTC
  • mfrom: (1.2.1) (9 sid)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: package-import@ubuntu.com-20130224192315-qhmwp3m3ymk8r60d
Tags: 2.2.0.1-1
* New upstream release
* relicense debian packaging to LGPL-3
* update watch file to use github directly
  thanks to Bart Martens for the file
* add autopkgtests
* drop obsolete DM-Upload-Allowed
* bump standard to 3.9.4, no changes required

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#
19
19
 
20
20
import sys
 
21
import time
21
22
import zmq
22
 
import time
23
 
 
24
 
def main ():
25
 
    use_poll = '-p' in sys.argv
26
 
    use_copy = '-c' in sys.argv
 
23
 
 
24
 
 
25
def main (argv):
 
26
    use_poll = '-p' in argv
 
27
    use_copy = '-c' in argv
27
28
    if use_copy:
28
 
        sys.argv.remove('-c')
 
29
        argv.remove('-c')
29
30
    if use_poll:
30
 
        sys.argv.remove('-p')
 
31
        argv.remove('-p')
31
32
 
32
 
    if len (sys.argv) != 4:
33
 
        print 'usage: remote_thr [-c use-copy] [-p use-poll] <connect-to> <message-size> <message-count>'
 
33
    if len (argv) != 4:
 
34
        print ('usage: remote_thr [-c use-copy] [-p use-poll] <connect-to> <message-size> <message-count>')
34
35
        sys.exit(1)
35
36
 
36
37
    try:
37
 
        connect_to = sys.argv[1]
38
 
        message_size = int(sys.argv[2])
39
 
        message_count = int(sys.argv[3])
40
 
    except (ValueError, OverflowError), e:
41
 
        print 'message-size and message-count must be integers'
 
38
        connect_to = argv[1]
 
39
        message_size = int(argv[2])
 
40
        message_count = int(argv[3])
 
41
    except (ValueError, OverflowError):
 
42
        print ('message-size and message-count must be integers')
42
43
        sys.exit(1)
43
44
 
44
45
    ctx = zmq.Context()
52
53
        p.register(s)
53
54
 
54
55
    s.connect(connect_to)
55
 
 
56
 
    # Wait for this side to connect.
57
 
    time.sleep(2.0)
58
 
 
59
 
    msg = ' ' * message_size
60
 
 
61
 
    for i in range(0, message_count):
 
56
    
 
57
    # remove the b for Python2.5:
 
58
    msg = zmq.Message(b' ' * message_size)
 
59
    block = zmq.NOBLOCK if use_poll else 0
 
60
    
 
61
    for i in range(message_count):
62
62
        if use_poll:
63
63
            res = p.poll()
64
64
            assert(res[0][1] & zmq.POLLOUT)
65
 
        s.send(msg, zmq.NOBLOCK if use_poll else 0, copy=use_copy)
 
65
        s.send(msg, block, copy=use_copy)
66
66
 
67
 
    # Let the context finish messaging before ending.
68
 
    # You may need to increase this time for longer or many messages.
69
 
    time.sleep(2.0)
 
67
    s.close()
 
68
    ctx.term()
70
69
 
71
70
if __name__ == "__main__":
72
 
    main ()
 
71
    main (sys.argv)