@@ -956,24 +956,24 @@ def forker():
956956 print ("ERR:" , err )
957957
958958 @needs_external_compilers
959- @linux_only # os. fork required.
959+ @linux_only # fork required.
960960 def test_lifetime_of_task_scheduler_handle (self ):
961961 # See PR #7280 for context.
962962 BROKEN_COMPILERS = 'SKIP: COMPILATION FAILED'
963963 runme = """if 1:
964964 import ctypes
965- import os
966965 import sys
966+ import multiprocessing as mp
967967 from tempfile import TemporaryDirectory, NamedTemporaryFile
968968 from numba.pycc.platform import Toolchain, _external_compiler_ok
969969 from numba import njit, prange, threading_layer
970-
970+ import faulthandler
971+ faulthandler.enable()
971972 if not _external_compiler_ok:
972973 raise AssertionError('External compilers are not found.')
973-
974- try:
975- with TemporaryDirectory() as tmpdir:
976- with NamedTemporaryFile(dir=tmpdir) as tmpfile:
974+ with TemporaryDirectory() as tmpdir:
975+ with NamedTemporaryFile(dir=tmpdir) as tmpfile:
976+ try:
977977 src = \" \" \"
978978 #define TBB_PREVIEW_WAITING_FOR_WORKERS 1
979979 #include <tbb/tbb.h>
@@ -999,31 +999,42 @@ def test_lifetime_of_task_scheduler_handle(self):
999999 # Load into the process, it doesn't matter whether the
10001000 # DSO exists on disk once it's loaded in.
10011001 DLL = ctypes.CDLL(dso_name)
1002- except Exception as e:
1003- # Something is broken in compilation, could be one of many
1004- # things including, but not limited to: missing tbb headers,
1005- # incorrect permissions, compilers that don't work for the above
1006- print(e)
1007- print('BROKEN_COMPILERS')
1008- sys.exit(0)
1009-
1010- # Do the test
1011- DLL.launch()
1002+ except Exception as e:
1003+ # Something is broken in compilation, could be one of
1004+ # many things including, but not limited to: missing tbb
1005+ # headers, incorrect permissions, compilers that don't
1006+ # work for the above
1007+ print(e)
1008+ print('BROKEN_COMPILERS')
1009+ sys.exit(0)
1010+
1011+ # Do the test, launch this library and also execute a
1012+ # function with the TBB threading layer.
1013+
1014+ DLL.launch()
1015+
1016+ @njit(parallel=True)
1017+ def foo(n):
1018+ acc = 0
1019+ for i in prange(n):
1020+ acc += i
1021+ return acc
1022+
1023+ foo(1)
1024+
1025+ # Check the threading layer used was TBB
1026+ assert threading_layer() == 'tbb'
10121027
1013- @njit(parallel=True)
1014- def foo(n):
1015- acc = 0
1016- for i in prange(n):
1017- acc += i
1018- return acc
1028+ # Use mp context for a controlled version of fork, this triggers the
1029+ # reported bug.
10191030
1020- foo(1 )
1021- assert threading_layer() == 'tbb'
1022- pid = os.fork()
1023- if pid != 0:
1024- # parent prints success
1025- print("SUCCESS" )
1026- sys.exit(0 )
1031+ ctx = mp.get_context('fork' )
1032+ def nowork():
1033+ pass
1034+ p = ctx.Process(target=nowork)
1035+ p.start()
1036+ p.join(10 )
1037+ print("SUCCESS" )
10271038 """ .replace ('BROKEN_COMPILERS' , BROKEN_COMPILERS )
10281039
10291040 cmdline = [sys .executable , '-c' , runme ]
0 commit comments