I'm trying to get a proxy class working, but it does not really want to work. The class that I want to proxy is the following:
import zmq
class ZmqPublish():
def __init__(self):
self.context = None
self.pub_socket = None
def setup(self, addr):
self.context = zmq.Context()
if isinstance(addr, str):
addr = addr.split(':')
host, port = addr if len(addr) == 2 else (addr[0], None)
self.pub_socket = self.context.socket(zmq.PUB)
self.pub_socket.bind('tcp://%s:%s' % (host, port))
def send(self, msg_type, msg):
self.pub_socket.send_multipart([msg_type, msg])
This simply starts a publisher and has the ability to send messages. Then I have another class that takes care of storing data and sending messages as well as a kind of reply:
from multiprocessing import Manager
from multiprocessing.managers import BaseManager
import zmq_publish
class publishManager(BaseManager):
pass
publishManager.register('zmq_publish.ZmqPublish', zmq_publish.ZmqPublish)
class Storage:
def __init__(self):
self.manager = Manager()
self.dict = self.manager.dict()
# Additional variables
self.host = '127.0.0.1'
self.port = 5555
self.bind_addr = (self.host, self.port)
self.publishManager = Storage.publishManager()
self.publishManager.start()
self.publishManager.setup(self.bind_addr)
def setup(self):
# Set up zmq subscriber with callbacks
def add(self, msg):
self.dict[msg] = 0
self.publishManager.send('type', msg)
For example the add function is given to a zmq process as a callback and it adds some information. The idea is that it can also send a message back as a response. The problem is, that the message is never send and I believe it is due to the fact that the callback process is another one than the one who created the publisher instance. Thus I am trying to proxy this class and make it available through a manager, but so far it does not work. Can somebody help me or give me some hints?
Kind regards Patrick