Skip to content

Commit 4954c5b

Browse files
Apply changes
1 parent fb83942 commit 4954c5b

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

batchflow/plotter/plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
# Decorators
2929
def detachable(func):
30-
""" Run `func` in a daemon process without result return.
30+
""" Run `func` in a daemon thread without result return.
3131
3232
Note, the decorator intercept the `detach` argument from the `func`.
3333
"""

batchflow/tests/detachable_test.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,18 @@
1010

1111
import os
1212
import tempfile
13+
import time
1314

1415
import numpy as np
1516

1617

18+
def _wait_for_file(path, timeout=5):
19+
"""Poll until `path` exists or `timeout` seconds elapse."""
20+
deadline = time.monotonic() + timeout
21+
while not os.path.exists(path) and time.monotonic() < deadline:
22+
time.sleep(0.05)
23+
24+
1725
def test_detachable_plot_with_detach():
1826
"""Plot.plot with detach=True should complete without PicklingError."""
1927
from batchflow.plotter.plot import Plot
@@ -22,11 +30,9 @@ def test_detachable_plot_with_detach():
2230
with tempfile.TemporaryDirectory() as tmpdir:
2331
savepath = os.path.join(tmpdir, "test_detach.png")
2432
p = Plot(data=data, mode="image", show=False, detach=True, savepath=savepath)
25-
# detach=True runs in a daemon thread — give it a moment to finish
26-
import time
27-
time.sleep(1)
28-
# The plot object should have been created without error
33+
_wait_for_file(savepath)
2934
assert p is not None
35+
assert os.path.exists(savepath)
3036

3137

3238
def test_plot_save_with_detach():
@@ -41,10 +47,7 @@ def test_plot_save_with_detach():
4147

4248
savepath2 = os.path.join(tmpdir, "test_save_detach2.png")
4349
p.save(savepath=savepath2, detach=True)
44-
import time
45-
deadline = time.monotonic() + 5
46-
while not os.path.exists(savepath2) and time.monotonic() < deadline:
47-
time.sleep(0.05)
50+
_wait_for_file(savepath2)
4851
assert os.path.exists(savepath2)
4952

5053

0 commit comments

Comments
 (0)