1👍
✅
You can get all instance with gc.get_objects
so:
import gc
class ExampleConsumer(AsyncWebsocketConsumer):
async def connect(self):
self.id = 1
self.foo = 'bar'
await self.accept()
def get_inc(cls):
return [obj for obj in gc.get_objects() if isinstance(obj, cls)]
for i in get_inc(ExampleConsumer):
print(i.foo)
Source:stackexchange.com