8000 gh-116167: Allow disabling the GIL with `PYTHON_GIL=0` or `-X gil=0` by swtaarrs · Pull Request #116338 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-116167: Allow disabling the GIL with PYTHON_GIL=0 or -X gil=0 #116338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 11, 2024
Prev Previous commit
Next Next commit
Add test for PYTHON_GIL in test_cmd_line
  • Loading branch information
swtaarrs committed Mar 5, 2024
commit 4f43a87ea9b80c210c9f70793a190a2c6f85c0f2
32 changes: 32 additions & 0 deletions Lib/test/test_cmd_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,38 @@ def test_pythondevmode_env(self):
self.assertEqual(proc.stdout.rstrip(), 'True')
self.assertEqual(proc.returncode, 0, proc)

@unittest.skipUnless(support.Py_GIL_DISABLED,
"PYTHON_GIL only supported in Py_GIL_DISABLED builds")
def test_python_gil_env(self):
code = """if 1:
import _testinternalcapi
print(_testinternalcapi.get_configs()['config'].get('enable_gil'))
"""
args = [sys.executable, '-c', code]
env = dict(os.environ)
env.pop('PYTHON_GIL', None)

def run():
return subprocess.run(args, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, text=True, env=env)

proc = run()
self.assertEqual(proc.returncode, 0, proc)
self.assertEqual(proc.stdout.rstrip(), '0')
self.assertEqual(proc.stderr, '')

env['PYTHON_GIL'] = '0'
proc = run()
self.assertEqual(proc.returncode, 0, proc)
self.assertEqual(proc.stdout.rstrip(), '1')
self.assertEqual(proc.stderr, '')

env['PYTHON_GIL'] = '1'
proc = run()
self.assertEqual(proc.returncode, 0, proc)
self.assertEqual(proc.stdout.rstrip(), '2')
self.assertEqual(proc.stderr, '')

@unittest.skipUnless(sys.platform == 'win32',
'bpo-32457 only applies on Windows')
def test_argv0_normalization(self):
Expand Down
0