Skip to content

Commit 9accf88

Browse files
authored
Merge pull request #2673 from ERGO-Code/bc/fix-2641
Fix #2641: avoid circular references in highspy
2 parents 9e8322a + 263398e commit 9accf88

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

highs/highspy/highs.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from itertools import product
66
from threading import Thread, local, RLock, Lock
77
from typing import Optional, Any, overload, Callable, Sequence, Mapping, Iterable, SupportsIndex, cast, Union, Tuple
8+
from weakref import proxy
89

910
from ._core import (
1011
ObjSense,
@@ -1446,7 +1447,7 @@ def __init__(self, callback_type: cb.HighsCallbackType, highs: Highs):
14461447
self.callbacks: list[Callable[[HighsCallbackEvent], None]] = []
14471448
self.user_callback_data: list[Any] = []
14481449
self.callback_type = callback_type
1449-
self.highs = highs
1450+
self.highs = proxy(highs) # to avoid circular reference
14501451

14511452
def subscribe(
14521453
self,
@@ -1617,7 +1618,7 @@ class highs_var(object):
16171618

16181619
def __init__(self, i: int, highs: Highs):
16191620
self.index = i
1620-
self.highs = highs
1621+
self.highs = proxy(highs) # to avoid circular reference
16211622

16221623
def __repr__(self):
16231624
return f"highs_var({self.index})"
@@ -1711,7 +1712,7 @@ class highs_cons(object):
17111712

17121713
def __init__(self, i: int, highs: Highs):
17131714
self.index = i
1714-
self.highs = highs
1715+
self.highs = proxy(highs) # to avoid circular reference
17151716

17161717
def __repr__(self):
17171718
return f"highs_cons({self.index})"

0 commit comments

Comments
 (0)