2
2
3
3
import gc
4
4
import multiprocessing
5
+ import signal
6
+ import sys
5
7
import weakref
6
8
7
9
import pytest
14
16
15
17
16
18
try :
19
+ import multiprocessing
20
+
17
21
spawn_context = multiprocessing .get_context ("spawn" )
18
- except ValueError :
22
+ except ( ImportError , ValueError ) :
19
23
spawn_context = None
20
24
21
25
@@ -51,9 +55,9 @@ def manual_new_target():
51
55
# The C++ compiler initializes container correctly.
52
56
assert vec .size () == 0
53
57
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
57
61
vec .append (1 )
58
62
vec .append (2 )
59
63
vec .append (3 )
@@ -64,13 +68,18 @@ def manual_new_target():
64
68
# guaranteed to work everywhere. It is marked as non-strict xfail.
65
69
@pytest .mark .xfail (reason = XFAIL_REASON , raises = SystemError , strict = False )
66
70
@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
+ )
67
75
def test_manual_new ():
68
76
process = spawn_context .Process (
69
77
target = manual_new_target ,
70
78
name = "manual_new_target" ,
71
79
)
72
80
process .start ()
73
81
process .join ()
82
+ assert abs (process .exitcode ) in (0 , signal .SIGSEGV , signal .SIGABRT )
74
83
if process .exitcode != 0 :
75
84
raise SystemError (
76
85
"Segmentation Fault: The C++ compiler initializes container incorrectly."
0 commit comments