Skip to content

Commit 1cc1e8e

Browse files
fix context manager api in idowner
1 parent a1b986d commit 1cc1e8e

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

notebooks/experiments.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import marimo
22

3-
__generated_with = "0.9.30"
3+
__generated_with = "0.9.32"
44
app = marimo.App()
55

66

77
@app.cell
88
def __():
99
import maturin_import_hook
1010
maturin_import_hook.install(settings=maturin_import_hook.MaturinSettings(release=True))
11-
return (maturin_import_hook,)
11+
import tribles
12+
return maturin_import_hook, tribles
1213

1314

1415
@app.cell
@@ -17,12 +18,6 @@ def __():
1718
return (mo,)
1819

1920

20-
@app.cell
21-
def __():
22-
import tribles
23-
return (tribles,)
24-
25-
2621
@app.cell
2722
def __():
2823
import sys
@@ -97,6 +92,26 @@ def __(tribles):
9792
return (Value,)
9893

9994

95+
@app.cell
96+
def __(tribles):
97+
IdOwner = tribles.IdOwner
98+
return (IdOwner,)
99+
100+
101+
@app.cell
102+
def __(IdOwner):
103+
owner = IdOwner()
104+
with owner.lock() as o:
105+
o.rngid()
106+
107+
return o, owner
108+
109+
110+
@app.cell
111+
def __():
112+
return
113+
114+
100115
@app.cell
101116
def __(FR256LE, Value, fractions):
102117
Value.of(FR256LE, fractions.Fraction(1,2)).to(fractions.Fraction)
@@ -581,8 +596,15 @@ def __(Id):
581596

582597

583598
@app.cell
584-
def __(Id, bench_consume, element_count_exp, experiments, time_ns):
585-
_experiment = Id.genid()
599+
def __(
600+
Id,
601+
IdOwner,
602+
bench_consume,
603+
element_count_exp,
604+
experiments,
605+
time_ns,
606+
):
607+
_experiment = IdOwner.genid()
586608
bench_insert_consume_data = experiments.entity({Id: _experiment, "label": "consume"})
587609
for _i in range(element_count_exp):
588610
bench_insert_consume_data += experiments.entity(

src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,13 @@ impl PyIdOwnerGuard {
186186
self.0 = None;
187187
}
188188

189-
pub fn __exit__(&mut self) {
189+
pub fn __enter__(slf: PyRef<Self>) -> PyRef<Self> {
190+
slf
191+
}
192+
193+
pub fn __exit__(&mut self, _exc_type: PyObject, _exc_value: PyObject, _traceback: PyObject) -> bool {
190194
self.release();
195+
false
191196
}
192197
}
193198

@@ -409,6 +414,7 @@ impl PyQuery {
409414
pub fn tribles_python(m: &Bound<'_, PyModule>) -> PyResult<()> {
410415
m.add_class::<PyTribleSet>()?;
411416
m.add_class::<PyId>()?;
417+
m.add_class::<PyIdOwner>()?;
412418
m.add_class::<PyValue>()?;
413419
m.add_class::<PyVariable>()?;
414420
m.add_class::<PyConstraint>()?;

0 commit comments

Comments
 (0)