'ZMQ - Multiple workers with the same socket Dealer

I have a Python package with the purpose of serving as Dealer to several pieces of code scattered in my solution. But until now it was only being used in a Django Views, so within an application. But now I would like to use this package in a separate script and it seems to me that the script is failing to execute zmq.Context.instance().socket(zmq.DEALER).connect(SOCKET_ADDR) because it is already being used by views.py. Does it make sense?

dealer.py (package):

imports...

context = zmq.Context.instance()
workerCnctn = context.socket(zmq.DEALER)
workerCnctn.identity = 'xxxxx'
workerCnctn.setsockopt(zmq.LINGER, 0)
workerCnctn.connect(SOCKET_ADDR)

class A:
    def __init__(self): 
        self.workerCnctn = workerCnctn
    def send(self, arg1, arg2):
        ...
        self.workerCnctn.send_string(msg)

views.py:

imports ...
import dealer

...

@api_view(["POST"])
def send(request):
    ...
    dealer = dealer.A()
    A.send(arg1, arg2)
    ...

script.py:

imports ...
import dealer

...
    
def main():
    ...
    dealer = dealer.A()
    A.send(arg1, arg2)
    ...

The script is to be called manually and the Django application is running constantly. What I noticed is that in the logs of the Router I can only catch messages that come from views.py.

So I ask, can't I have different workers with the same purpose using the same socket?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source