Skip to content

Commit 0ff01de

Browse files
rgommerstylerjereddy
authored andcommitted
TST: fix thread safety issue in interpolate.bsplines memmap test
This test was recently introduced in scipygh-22158. It causes a crash when running the test suite with `pytest-run-parallel`, because of writing to the same tempfile from multiple threads. [skip cirrus] [skip circle]
1 parent 21c65ab commit 0ff01de

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

scipy/interpolate/tests/test_bsplines.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import operator
33
import itertools
44
import math
5+
import threading
56

67
import numpy as np
78
from numpy.testing import suppress_warnings
@@ -658,11 +659,12 @@ def test_memmap(self, tmpdir):
658659

659660
expected = b(xx)
660661

661-
t_mm = np.memmap(
662-
str(tmpdir.join('t.dat')), mode='w+', dtype=b.t.dtype, shape=b.t.shape)
662+
tid = threading.get_native_id()
663+
t_mm = np.memmap(str(tmpdir.join(f't{tid}.dat')), mode='w+',
664+
dtype=b.t.dtype, shape=b.t.shape)
663665
t_mm[:] = b.t
664-
c_mm = np.memmap(
665-
str(tmpdir.join('c.dat')), mode='w+', dtype=b.c.dtype, shape=b.c.shape)
666+
c_mm = np.memmap(str(tmpdir.join(f'c{tid}.dat')), mode='w+',
667+
dtype=b.c.dtype, shape=b.c.shape)
666668
c_mm[:] = b.c
667669
b.t = t_mm
668670
b.c = c_mm

0 commit comments

Comments
 (0)