When publishing with this code in python3, an unexpected and unsolvable error happens:
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
from twisted.application import service
from txzmq import ZmqFactory, ZmqEndpoint, ZmqPubConnection
from twisted.internet import reactor
import time
class ZmqPubSubService(service.Service):
def __init__(self):
self.zf = ZmqFactory()
def publish(self):
data = str(time.time()).encode('ascii')
print("Publishing {}".format(data))
self.subconn.publish(data, b'test')
reactor.callLater(1, self.publish)
def startService(self):
self.sube = ZmqEndpoint('bind', 'tcp://127.0.0.1:5557')
self.push = ZmqEndpoint('bind', 'tcp://127.0.0.1:5558')
self.subconn = ZmqPubConnection(self.zf, self.sube)
self.publish()
def stopService(self):
del self.sube
del self.push
del self.subconn
#return self.tcpService.stopService()
2016-01-09 21:13:36+0100 [-] Publishing b'1452370416.7726436'
2016-01-09 21:13:36+0100 [-] Traceback (most recent call last):
2016-01-09 21:13:36+0100 [-] File "/home/dk/develop/con2/env/bin/cond", line 9, in <module>
2016-01-09 21:13:36+0100 [-] load_entry_point('con2==2.0', 'console_scripts', 'cond')()
2016-01-09 21:13:36+0100 [-] File "/home/dk/develop/con2/src/con2/scripts/cond_run.py", line 12, in main
2016-01-09 21:13:36+0100 [-] run()
2016-01-09 21:13:36+0100 [-] File "/home/dk/develop/con2/env/lib/python3.4/site-packages/Twisted-15.5.0-py3.4.egg/twisted/scripts/twistd.py", line 29, in run
2016-01-09 21:13:36+0100 [-] app.run(runApp, ServerOptions)
2016-01-09 21:13:36+0100 [-] File "/home/dk/develop/con2/env/lib/python3.4/site-packages/Twisted-15.5.0-py3.4.egg/twisted/application/app.py", line 617, in run
2016-01-09 21:13:36+0100 [-] runApp(config)
2016-01-09 21:13:36+0100 [-] File "/home/dk/develop/con2/env/lib/python3.4/site-packages/Twisted-15.5.0-py3.4.egg/twisted/scripts/twistd.py", line 25, in runApp
2016-01-09 21:13:36+0100 [-] _SomeApplicationRunner(config).run()
2016-01-09 21:13:36+0100 [-] File "/home/dk/develop/con2/env/lib/python3.4/site-packages/Twisted-15.5.0-py3.4.egg/twisted/application/app.py", line 352, in run
2016-01-09 21:13:36+0100 [-] self.postApplication()
2016-01-09 21:13:36+0100 [-] File "/home/dk/develop/con2/env/lib/python3.4/site-packages/Twisted-15.5.0-py3.4.egg/twisted/scripts/_twistd_unix.py", line 207, in postApplication
2016-01-09 21:13:36+0100 [-] self.startApplication(self.application)
2016-01-09 21:13:36+0100 [-] File "/home/dk/develop/con2/env/lib/python3.4/site-packages/Twisted-15.5.0-py3.4.egg/twisted/scripts/_twistd_unix.py", line 403, in startApplication
2016-01-09 21:13:36+0100 [-] app.startApplication(application, not self.config['no_save'])
2016-01-09 21:13:36+0100 [-] File "/home/dk/develop/con2/env/lib/python3.4/site-packages/Twisted-15.5.0-py3.4.egg/twisted/application/app.py", line 633, in startApplication
2016-01-09 21:13:36+0100 [-] service.IService(application).startService()
2016-01-09 21:13:36+0100 [-] File "/home/dk/develop/con2/env/lib/python3.4/site-packages/Twisted-15.5.0-py3.4.egg/twisted/application/service.py", line 283, in startService
2016-01-09 21:13:36+0100 [-] service.startService()
2016-01-09 21:13:36+0100 [-] File "/home/dk/develop/con2/src/con2/services/zmq_pubsub.py", line 27, in startService
2016-01-09 21:13:36+0100 [-] self.publish()
2016-01-09 21:13:36+0100 [-] File "/home/dk/develop/con2/src/con2/services/zmq_pubsub.py", line 19, in publish
2016-01-09 21:13:36+0100 [-] self.subconn.publish(data, b'test')
2016-01-09 21:13:36+0100 [-] File "/home/dk/develop/con2/env/lib/python3.4/site-packages/txZMQ-0.7.4-py3.4.egg/txzmq/pubsub.py", line 26, in publish
2016-01-09 21:13:36+0100 [-] self.send(tag + b'\0' + message)
2016-01-09 21:13:36+0100 [-] File "/home/dk/develop/con2/env/lib/python3.4/site-packages/txZMQ-0.7.4-py3.4.egg/txzmq/connection.py", line 312, in send
2016-01-09 21:13:36+0100 [-] self.socket.send(m, constants.NOBLOCK | constants.SNDMORE)
2016-01-09 21:13:36+0100 [-] File "zmq/backend/cython/socket.pyx", line 617, in zmq.backend.cython.socket.Socket.send (zmq/backend/cython/socket.c:6625)
2016-01-09 21:13:36+0100 [-] File "zmq/backend/cython/socket.pyx", line 664, in zmq.backend.cython.socket.Socket.send (zmq/backend/cython/socket.c:6363)
2016-01-09 21:13:36+0100 [-] File "zmq/backend/cython/socket.pyx", line 184, in zmq.backend.cython.socket._send_copy (zmq/backend/cython/socket.c:2361)
2016-01-09 21:13:36+0100 [-] File "zmq/utils/buffers.pxd", line 200, in buffers.asbuffer_r (zmq/backend/cython/socket.c:8652)
2016-01-09 21:13:36+0100 [-] File "zmq/utils/buffers.pxd", line 151, in buffers.asbuffer (zmq/backend/cython/socket.c:7985)
2016-01-09 21:13:36+0100 [-] TypeError: 116 does not provide a buffer interface.
def send(self, message):
"""
Send message via ZeroMQ socket.
Sending is performed directly to ZeroMQ without queueing. If HWM is
reached on ZeroMQ side, sending operation is aborted with exception
from ZeroMQ (EAGAIN).
After writing read is scheduled as ZeroMQ may not signal incoming
messages after we touched socket with write request.
:param message: message data, could be either list of str (multipart
message) or just str
:type message: str or list of str
"""
if not hasattr(message, '__iter__'):
self.socket.send(message, constants.NOBLOCK)
else:
for m in message[:-1]:
self.socket.send(m, constants.NOBLOCK | constants.SNDMORE)
self.socket.send(message[-1], constants.NOBLOCK)