22
33import gc
44import multiprocessing
5+ import signal
6+ import sys
57import weakref
68
79import pytest
1416
1517
1618try :
19+ import multiprocessing
20+
1721 spawn_context = multiprocessing .get_context ("spawn" )
18- except ValueError :
22+ except ( ImportError , ValueError ) :
1923 spawn_context = None
2024
2125
@@ -51,9 +55,9 @@ def manual_new_target():
5155 # The C++ compiler initializes container correctly.
5256 assert vec .size () == 0
5357 else :
54- raise SystemError (
55- "Segmentation Fault: The C++ compiler initializes container incorrectly."
56- )
58+ # The program is not supposed to reach here. It will abort with
59+ # SIGSEGV on `vec.is_empty()`.
60+ sys . exit ( signal . SIGSEGV ) # manually trigger SIGSEGV if not raised
5761 vec .append (1 )
5862 vec .append (2 )
5963 vec .append (3 )
@@ -64,13 +68,18 @@ def manual_new_target():
6468# guaranteed to work everywhere. It is marked as non-strict xfail.
6569@pytest .mark .xfail (reason = XFAIL_REASON , raises = SystemError , strict = False )
6670@pytest .mark .skipif (spawn_context is None , reason = "spawn context not available" )
71+ @pytest .mark .skipif (
72+ sys .platform .startswith ("emscripten" ),
73+ reason = "Requires multiprocessing" ,
74+ )
6775def test_manual_new ():
6876 process = spawn_context .Process (
6977 target = manual_new_target ,
7078 name = "manual_new_target" ,
7179 )
7280 process .start ()
7381 process .join ()
82+ assert abs (process .exitcode ) in (0 , signal .SIGSEGV , signal .SIGABRT )
7483 if process .exitcode != 0 :
7584 raise SystemError (
7685 "Segmentation Fault: The C++ compiler initializes container incorrectly."
0 commit comments