@@ -110,3 +110,42 @@ def kernel(start, stop, nitems):
110110 f"stdout:\n { result .stdout } \n "
111111 f"stderr:\n { result .stderr } "
112112 )
113+
114+
115+ def test_windows_dsl_scalar_only_flat_idx_shutdown_stress ():
116+ """Run the original minimal subprocess many times to catch intermittent Windows AVs."""
117+ if blosc2 .IS_WASM :
118+ pytest .skip ("subprocess is not supported on emscripten/wasm32" )
119+
120+ code = textwrap .dedent (
121+ """
122+ import numpy as np
123+ import blosc2
124+
125+ @blosc2.dsl_kernel
126+ def kernel(start, stop, nitems):
127+ step = (float(stop) - float(start)) / float(nitems)
128+ return float(start) + _flat_idx * step # noqa: F821
129+
130+ shape = (10, 100)
131+ arr = blosc2.lazyudf(kernel, (-10, 10, 999), dtype=np.float32, shape=shape).compute()
132+ exp = np.linspace(-10, 10, np.prod(shape), dtype=np.float32).reshape(shape)
133+ np.testing.assert_allclose(arr, exp, rtol=1e-6, atol=1e-6)
134+ print("ok", flush=True)
135+ """
136+ )
137+
138+ nrepeat = 100 if sys .platform == "win32" else 5
139+ with tempfile .TemporaryDirectory () as tmpdir :
140+ script = Path (tmpdir ) / "dsl_shutdown_stress.py"
141+ script .write_text (code , encoding = "utf-8" )
142+ for i in range (nrepeat ):
143+ result = subprocess .run (
144+ [sys .executable , str (script )], capture_output = True , text = True , check = False
145+ )
146+ assert result .returncode == 0 , (
147+ f"subprocess failed on iteration { i + 1 } /{ nrepeat } : returncode={ result .returncode } \n "
148+ f"stdout:\n { result .stdout } \n "
149+ f"stderr:\n { result .stderr } "
150+ )
151+ assert "ok" in result .stdout
0 commit comments