Posts

Showing posts with the label pyzmq

Why doesn't this async code stop?

Why doesn't this async code stop? The following code snippet has two coroutines each for server and client. The client coroutine has a logic to break the while loop after 10 seconds and server should stop after 15 seconds. while When I run the script this doesn't stop, ideally, it should stop after 15 seconds but this is not happening. import asyncio import time import zmq import zmq.asyncio zmq.asyncio.install() ctx = zmq.asyncio.Context() server_socket = ctx.socket(zmq.REP) client_socket = ctx.socket(zmq.REQ) server_socket.bind("tcp://127.0.0.1:8899") client_socket.connect("tcp://127.0.0.1:8899") t0 = time.time() @asyncio.coroutine def server_coroutine(): while True: msg = yield from server_socket.recv_string() print(msg) msg = "Server:: {}".format(msg) yield from server_socket.send_string(msg) t1 = time.time() elapsed_time = t1 - t0 # print('elapsed time is {}'.format(elapsed_t...