Skip to content

bpo-31294: Fix ZeroMQSocketListener and ZeroMQSocketHandler examples #3229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Doc/howto/logging-cookbook.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1258,8 +1258,8 @@ socket is created separately and passed to the handler (as its 'queue')::

class ZeroMQSocketHandler(QueueHandler):
def enqueue(self, record):
data = json.dumps(record.__dict__)
self.queue.send(data)
self.queue.send_json(record.__dict__)


handler = ZeroMQSocketHandler(sock)

Expand All @@ -1272,11 +1272,10 @@ data needed by the handler to create the socket::
self.ctx = ctx or zmq.Context()
socket = zmq.Socket(self.ctx, socktype)
socket.bind(uri)
QueueHandler.__init__(self, socket)
super().__init__(socket)

def enqueue(self, record):
data = json.dumps(record.__dict__)
self.queue.send(data)
self.queue.send_json(record.__dict__)

def close(self):
self.queue.close()
Expand All @@ -1292,12 +1291,13 @@ of queues, for example a ZeroMQ 'subscribe' socket. Here's an example::
def __init__(self, uri, *handlers, **kwargs):
self.ctx = kwargs.get('ctx') or zmq.Context()
socket = zmq.Socket(self.ctx, zmq.SUB)
socket.setsockopt(zmq.SUBSCRIBE, '') # subscribe to everything
socket.setsockopt_string(zmq.SUBSCRIBE, '') # subscribe to everything
socket.connect(uri)
super().__init__(socket, *handlers, **kwargs)

def dequeue(self):
msg = self.queue.recv()
return logging.makeLogRecord(json.loads(msg))
msg = self.queue.recv_json()
return logging.makeLogRecord(msg)


.. seealso::
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,7 @@ Martin Teichmann
Gustavo Temple
Mikhail Terekhov
Victor Terrón
Pablo Galindo
Richard M. Tew
Tobias Thelen
Christian Theune
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix incomplete code snippet in the ZeroMQSocketListener and
ZeroMQSocketHandler examples and adapt them to Python 3.