diff options
author | 2015-08-24 13:22:48 +0300 | |
---|---|---|
committer | 2015-08-24 13:22:48 +0300 | |
commit | dab741a80699f86e86c91718872a052cca9bbb25 (patch) | |
tree | 1959c4a2cea440170a5113dcb067796cb20ffb64 /external_libs/python/pyzmq-14.7.0/examples/gevent/simple.py | |
parent | d3f26ece7d4383df0b22fe9c3cb3e695381ec737 (diff) |
Fixed dependencies of Control Plane to use external_lib sources
Diffstat (limited to 'external_libs/python/pyzmq-14.7.0/examples/gevent/simple.py')
-rw-r--r-- | external_libs/python/pyzmq-14.7.0/examples/gevent/simple.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/external_libs/python/pyzmq-14.7.0/examples/gevent/simple.py b/external_libs/python/pyzmq-14.7.0/examples/gevent/simple.py new file mode 100644 index 00000000..ae065b35 --- /dev/null +++ b/external_libs/python/pyzmq-14.7.0/examples/gevent/simple.py @@ -0,0 +1,37 @@ +from gevent import spawn, spawn_later +import zmq.green as zmq + +# server +print zmq.Context +ctx = zmq.Context() +sock = ctx.socket(zmq.PUSH) +sock.bind('ipc:///tmp/zmqtest') + +spawn(sock.send_pyobj, ('this', 'is', 'a', 'python', 'tuple')) +spawn_later(1, sock.send_pyobj, {'hi': 1234}) +spawn_later(2, sock.send_pyobj, ({'this': ['is a more complicated object', ':)']}, 42, 42, 42)) +spawn_later(3, sock.send_pyobj, 'foobar') +spawn_later(4, sock.send_pyobj, 'quit') + + +# client +ctx = zmq.Context() # create a new context to kick the wheels +sock = ctx.socket(zmq.PULL) +sock.connect('ipc:///tmp/zmqtest') + +def get_objs(sock): + while True: + o = sock.recv_pyobj() + print 'received python object:', o + if o == 'quit': + print 'exiting.' + break + +def print_every(s, t=None): + print s + if t: + spawn_later(t, print_every, s, t) + +print_every('printing every half second', 0.5) +spawn(get_objs, sock).join() + |