Skip to content

Commit d0fcf30

Browse files
Fix threading tests
1 parent 01c2ef7 commit d0fcf30

File tree

1 file changed

+9
-24
lines changed

1 file changed

+9
-24
lines changed

python/tests/test_bindings.py

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import _thread
1+
import concurrent.futures
22
import json
33
import os
44
import pathlib
@@ -172,23 +172,6 @@ def test_sort_alias(self):
172172
Extract(DUMMY_SPAN, Var(DUMMY_SPAN, "my_map2"), Lit(DUMMY_SPAN, Int(0))),
173173
)
174174

175-
extract_report = egraph.extract_report()
176-
assert isinstance(extract_report, Best)
177-
assert extract_report.termdag.term_to_expr(extract_report.term, DUMMY_SPAN) == Call(
178-
DUMMY_SPAN,
179-
"map-insert",
180-
[
181-
Call(
182-
DUMMY_SPAN,
183-
"map-insert",
184-
[Call(DUMMY_SPAN, "map-empty", []), Lit(DUMMY_SPAN, Int(2)), Lit(DUMMY_SPAN, String("two"))],
185-
),
186-
Lit(DUMMY_SPAN, Int(1)),
187-
Lit(DUMMY_SPAN, String("one")),
188-
],
189-
)
190-
assert extract_report.cost == 4
191-
192175

193176
class TestVariant:
194177
def test_repr(self):
@@ -228,16 +211,18 @@ def test_cmds(self):
228211
),
229212
RunSchedule(Repeat(DUMMY_SPAN, 10, Run(DUMMY_SPAN, RunConfig("")))),
230213
)
231-
232-
_thread.start_new_thread(print, cmds)
214+
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:
215+
executor.submit(print, cmds).result()
233216

234217
@pytest.mark.xfail(reason="egraphs are unsendable")
235218
def test_egraph(self):
236-
_thread.start_new_thread(
237-
EGraph().run_program, (Datatype(DUMMY_SPAN, "Math", [Variant(DUMMY_SPAN, "Add", ["Math", "Math"])]),)
238-
)
219+
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:
220+
executor.submit(
221+
EGraph().run_program, Datatype(DUMMY_SPAN, "Math", [Variant(DUMMY_SPAN, "Add", ["Math", "Math"])])
222+
).result()
239223

240224
def test_serialized_egraph(self):
241225
egraph = EGraph()
242226
serialized = egraph.serialize([])
243-
_thread.start_new_thread(print, (serialized,))
227+
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:
228+
executor.submit(print, (serialized,)).result()

0 commit comments

Comments
 (0)