Skip to content

Instantly share code, notes, and snippets.

@indradhanush
Created June 16, 2014 08:20
Show Gist options
  • Save indradhanush/4448fc0d634e50441c69 to your computer and use it in GitHub Desktop.
Save indradhanush/4448fc0d634e50441c69 to your computer and use it in GitHub Desktop.
Reproducing blocking zmq.Context.term() vs Non blocking zmq.Context.destroy()
import zmq
# Server
class Server():
def __init__(self, context):
self.context = context
self.router = self.context.socket(zmq.ROUTER)
self.router.bind("tcp://127.0.0.1:9876")
def kill_server(self):
self.context.term()
# self.context.destroy()
# Client
class Client():
def __init__(self, context):
self.context = context
self.speaker = self.context.socket(zmq.DEALER)
self.speaker.connect("tcp://127.0.0.1:9876")
def kill_client(self):
self.context.term()
# self.context.destroy()
if __name__ == "__main__":
server = Server(zmq.Context())
client = Client(zmq.Context())
# This blocks.
client.kill_client()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment