I am trying to create singleton instance for each queue. If the instance is already created it should get connected to same instance or else create a new one. I have used the queue to create the queues.
from queue import Queue
class Singleton(Queue):
__instance = None
def __new__(cls):
if cls.__instance is None:
cls.__instance = super().__new__(cls)
return cls.__instance
class Queue(object):
def __init__(self,**kwargs):
self.queue = Singleton
print(id(self.queue))
class Interpretor(object):
def __init__(self,**kwargs):
self.queue = Singleton
print(id(self.queue))
I am getting the same queue id for both the queues
2611032512096
2611032512096