@@ -47,10 +47,18 @@ def _run_child_process(self, all_interpreters):
4747 import os
4848 import sys
4949 import _remote_debugging
50-
51- pid = int(sys.argv[1])
52- gc_stats = _remote_debugging.get_gc_stats(pid, all_interpreters={ all_interpreters } )
53- print(json.dumps(gc_stats, indent=1))
50+ try:
51+ from _remote_debugging import PROCESS_VM_READV_SUPPORTED
52+ supported = True
53+ except ImportError:
54+ supported = False
55+
56+ if supported:
57+ pid = int(sys.argv[1])
58+ gc_stats = _remote_debugging.get_gc_stats(pid, all_interpreters={ all_interpreters } )
59+ print(json.dumps(gc_stats, indent=1))
60+ else:
61+ print(json.dumps(dict([("error", "not supported")])))
5462 """ )
5563
5664 gc .collect (0 )
@@ -67,7 +75,13 @@ def _run_child_process(self, all_interpreters):
6775 result .returncode , 0 ,
6876 f"stdout: { result .stdout } \n stderr: { result .stderr } "
6977 )
70- return result
78+ data = json .loads (result .stdout )
79+ if isinstance (data , dict ) and "error" in data :
80+ if sys .platform == "linux" :
81+ self .skipTest ("Testing on Linux requires process_vm_readv support" )
82+ else :
83+ self .assertTrue (False , f"Unexpected error: { data } " )
84+ return data
7185
7286 def _run_in_interpreter (self , interp ):
7387 source = f"""if True:
@@ -104,8 +118,8 @@ def _check_gc_state(self, before, after):
104118 (before , after ))
105119
106120 def test_get_gc_stats_for_main_interpreter (self ):
107- before_stats = json . loads ( self ._run_child_process (False ). stdout )
108- after_stats = json . loads ( self ._run_child_process (False ). stdout )
121+ before_stats = self ._run_child_process (False )
122+ after_stats = self ._run_child_process (False )
109123
110124 before_iids = get_interpreter_identifiers (before_stats )
111125 after_iids = get_interpreter_identifiers (after_stats )
@@ -136,9 +150,9 @@ def test_get_gc_stats_for_all_interpreters(self):
136150 interp = interpreters .create ()
137151
138152 self ._run_in_interpreter (interp ) # ensure that subinterpeter have GC stats
139- before_stats = json . loads ( self ._run_child_process (True ). stdout )
153+ before_stats = self ._run_child_process (True )
140154 self ._run_in_interpreter (interp ) # ensure that GC stats in subinterpreter changed
141- after_stats = json . loads ( self ._run_child_process (True ). stdout )
155+ after_stats = self ._run_child_process (True )
142156 interp .close ()
143157
144158 before_iids = get_interpreter_identifiers (before_stats )
@@ -171,9 +185,9 @@ def test_get_gc_stats_for_main_interpreter_if_subinterpreter_exists(self):
171185 interp = interpreters .create ()
172186
173187 self ._run_in_interpreter (interp ) # ensure that subinterpeter have GC stats
174- before_stats = json . loads ( self ._run_child_process (False ). stdout )
188+ before_stats = self ._run_child_process (False )
175189 self ._run_in_interpreter (interp ) # ensure that GC stats in subinterpreter changed
176- after_stats = json . loads ( self ._run_child_process (False ). stdout )
190+ after_stats = self ._run_child_process (False )
177191 interp .close ()
178192
179193 before_iids = get_interpreter_identifiers (before_stats )
0 commit comments