circular-reference

Circular import with beanie ODM

Circular import with beanie ODM Question: I need to use a cross-reference in my MongoDB schema. I use beanie as ODM. Here is my models: entity.py from beanie import Document class Entity(Document): path: List["Folder"] = [] folder.py from entity import Entity class Folder(Entity) pass init_beanie.py import beanie from motor.motor_asyncio import AsyncIOMotorClient from entity import Entity …

Total answers: 1

Why isn't the __del__ method called?

Why isn't the __del__ method called? Question: In python3’s multiprocess, can’t call the __del__ method. I’ve read other issues about circular references,but I can’t find the situation in multiprocess. There is a circular reference in foo, __del__ will be called when foo is called directly,but in multiprocess the __del__ will never be called. import multiprocessing …

Total answers: 2

How and when to appropriately use weakref in Python

How and when to appropriately use weakref in Python Question: I have some code where instances of classes have parent<->child references to each other, e.g.: class Node: def __init__(self): self.parent = None self.children = {} def AddChild(self, name, child): child.parent = self self.children[name] = child def Run(): root, c1, c2 = Node(), Node(), Node() root.AddChild(‘first’, …

Total answers: 3