File: zmq_simple.py

package info (click to toggle)
python-eventlet 0.40.3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 3,200 kB
  • sloc: python: 25,109; sh: 78; makefile: 32
file content (38 lines) | stat: -rw-r--r-- 888 bytes parent folder | download | duplicates (5)
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
36
37
38
import eventlet

try:
    from eventlet.green import zmq
except ModuleNotFoundError:
    raise SystemExit("Unable to find required zmq module. "
                     "Please install it before running this example.")

CTX = zmq.Context(1)


def bob_client(ctx, count):
    print("STARTING BOB")
    bob = zmq.Socket(CTX, zmq.REQ)
    bob.connect("ipc:///tmp/test")

    for i in range(0, count):
        print("BOB SENDING")
        bob.send("HI")
        print("BOB GOT:", bob.recv())


def alice_server(ctx, count):
    print("STARTING ALICE")
    alice = zmq.Socket(CTX, zmq.REP)
    alice.bind("ipc:///tmp/test")

    print("ALICE READY")
    for i in range(0, count):
        print("ALICE GOT:", alice.recv())
        print("ALIC SENDING")
        alice.send("HI BACK")

alice = eventlet.spawn(alice_server, CTX, 10)
bob = eventlet.spawn(bob_client, CTX, 10)

bob.wait()
alice.wait()