summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2017-09-07 21:27:44 (GMT)
committerChristian Heimes <christian@python.org>2017-09-07 21:27:44 (GMT)
commit27ce5a1b1931b670da234c30d24bfbbc93fa24d7 (patch)
treedfc8542a333c1dc880af38afb381a4508fe8fd00
parente89b35dd2b87e85978b91e3e2dbdea1fc76d6be4 (diff)
downloadcpython-27ce5a1b1931b670da234c30d24bfbbc93fa24d7.zip
cpython-27ce5a1b1931b670da234c30d24bfbbc93fa24d7.tar.gz
cpython-27ce5a1b1931b670da234c30d24bfbbc93fa24d7.tar.bz2
[3.6] bpo-31294: Fix ZeroMQSocketListener and ZeroMQSocketHandler examples (GH-3229) (#3430)
* Fix ZeroMQSocketListener and ZeroMQSocketHandler examples * Use send_json and recv_json to simplify pyzmq interfacing * Add News entry (cherry picked from commit 586c0502b5eb9a39cabe0bc2707a8ff63114265c)
-rw-r--r--Doc/howto/logging-cookbook.rst16
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS.d/next/Documentation/2017-09-07-20-49-09.bpo-31294.WgI18w.rst2
3 files changed, 11 insertions, 8 deletions
diff --git a/Doc/howto/logging-cookbook.rst b/Doc/howto/logging-cookbook.rst
index 6498ea5..44f38e0 100644
--- a/Doc/howto/logging-cookbook.rst
+++ b/Doc/howto/logging-cookbook.rst
@@ -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)
@@ -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()
@@ -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::
diff --git a/Misc/ACKS b/Misc/ACKS
index 3b246c1..83336ec 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1537,6 +1537,7 @@ Martin Teichmann
Gustavo Temple
Mikhail Terekhov
Victor Terrón
+Pablo Galindo
Richard M. Tew
Tobias Thelen
Févry Thibault
diff --git a/Misc/NEWS.d/next/Documentation/2017-09-07-20-49-09.bpo-31294.WgI18w.rst b/Misc/NEWS.d/next/Documentation/2017-09-07-20-49-09.bpo-31294.WgI18w.rst
new file mode 100644
index 0000000..2c8f850
--- /dev/null
+++ b/Misc/NEWS.d/next/Documentation/2017-09-07-20-49-09.bpo-31294.WgI18w.rst
@@ -0,0 +1,2 @@
+Fix incomplete code snippet in the ZeroMQSocketListener and
+ZeroMQSocketHandler examples and adapt them to Python 3.