Python API: edge neighborhood nodes retain visitors after leaving scope
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Creating CompoundRegionOperationNode.new_edge_neighborhood leaves its Python visitor alive after the node wrapper and all Python references to the visitor have been dropped. Repeated construction accumulates visitors and any data attached to them. Calling Region.complex_op is not needed to reproduce this.
Expected: once the node and visitor are no longer referenced, the visitor can be collected.
Minimal reproduction:
import gc
import weakref
from typing import List, Tuple
import klayout.db as kdb
class Visitor(kdb.EdgeNeighborhoodVisitor):
def on_edge(self, layout: kdb.Layout, cell: kdb.Cell, edge: kdb.Edge, neighborhood: List):
pass
def make() -> Tuple[weakref.ReferenceType, weakref.ReferenceType]:
visitor = Visitor()
node = kdb.CompoundRegionOperationNode.new_edge_neighborhood(
children=[], visitor=visitor)
return weakref.ref(visitor), weakref.ref(node)
references = [make() for _ in range(100)]
gc.collect()
print("Visitors alive:", sum(visitor() is not None for visitor, _ in references))
print("Node wrappers alive:", sum(node() is not None for _, node in references))
Actual: 100 visitors and zero node wrappers remain alive.
Controls:
- Constructing and discarding visitors without constructing nodes leaves zero of 100 visitors alive
- Creating nodes without executing them leaves 1, 10 and 100 visitors alive after 1, 10 and 100 calls
- Executing
complex_opon ordinary flat rectangular regions gives the same 1, 10 and 100 counts - The node-only and flat-region reproductions also retain all 100 visitors on Linux with Python
3.12.3
The reproduction has no extraction context, DeepShapeStore, callback instrumentation or retained strong-reference collection. Its observation list contains only weak references.
This is distinct from #2495, which concerned retained on_edge arguments and was fixed by #2501. Here no callback needs to run. In KPEX, each visitor refers to the extraction results, so retained visitors can keep completed extraction data alive when operations are repeated in one process.
The v0.30.13 source appears consistent with this lifetime observation:
- The edge-neighborhood constructor calls
visitor->keep() - The node stores the visitor as a
tl::weak_ptr, with no matching visitor release in the class gsi::ObjectBase::keepmarks the object as owned by C++ rather than the script- The polygon-neighborhood constructor uses the same ownership pattern
Versions:
KLayoutPython module0.30.13, Python3.14.6, macOS26.6.2- Independent node-only and flat-region reproductions:
KLayoutPython module0.30.13, Python3.12.3, Linux - The
KLayoutexecutable is not involved - Source tag
v0.30.13, commit06b8ff4909ad1696c06c634183d8fd0eaa8a1b83
- Ngôn ngữ chính
- C++
- Star
- 1.2k
- Fork
- 305
- Merge trung bình
- 3 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 11
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của KLayout/klayout
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
KLayout/klayout#2554 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
KLayout/klayout#2412 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
DRC functions not working properly with clip in placeCó thể đã có người làm @klayoutmatthias đã nhận hôm nay. Đang mởbug
KLayout/klayout#2553 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 50/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Deep DRC can miss violations when a cell has many shapesCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
KLayout/klayout#2546 · 5 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của KLayout/klayout
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Integer underflow and buffer overrun in detail::count_rows on disconnected distance matricesĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
LaneDibello/Kotor-Patch-Manager#375 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày