Run code in a subinterpreter. Raise unittest.SkipTest if the tracemalloc module is enabled.
(code, *, own_gil=None, **config)
| 2037 | |
| 2038 | |
| 2039 | def run_in_subinterp_with_config(code, *, own_gil=None, **config): |
| 2040 | """ |
| 2041 | Run code in a subinterpreter. Raise unittest.SkipTest if the tracemalloc |
| 2042 | module is enabled. |
| 2043 | """ |
| 2044 | _check_tracemalloc() |
| 2045 | try: |
| 2046 | import _testinternalcapi |
| 2047 | except ImportError: |
| 2048 | raise unittest.SkipTest("requires _testinternalcapi") |
| 2049 | if own_gil is not None: |
| 2050 | assert 'gil' not in config, (own_gil, config) |
| 2051 | config['gil'] = 'own' if own_gil else 'shared' |
| 2052 | else: |
| 2053 | gil = config['gil'] |
| 2054 | if gil == 0: |
| 2055 | config['gil'] = 'default' |
| 2056 | elif gil == 1: |
| 2057 | config['gil'] = 'shared' |
| 2058 | elif gil == 2: |
| 2059 | config['gil'] = 'own' |
| 2060 | elif not isinstance(gil, str): |
| 2061 | raise NotImplementedError(gil) |
| 2062 | config = types.SimpleNamespace(**config) |
| 2063 | return _testinternalcapi.run_in_subinterp_with_config(code, config) |
| 2064 | |
| 2065 | |
| 2066 | def _check_tracemalloc(): |
no test coverage detected
searching dependent graphs…