File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99import sys
1010import posix
1111
12- _sentinel = posix.environ.get (b" PYTHON_CROSSENV" )
12+ # Handle subinterpreters -- everything should already be ready to go, but
13+ # the PYTHON_CROSSENV environment variable won't be set because we're running
14+ # in the same process
15+ _sentinel = None
16+ try:
17+ import concurrent.interpreters
18+ except ImportError:
19+ pass
20+ else :
21+ if concurrent.interpreters.get_current () != concurrent.interpreters.get_main ():
22+ _sentinel = b" {{context.sentinel}}"
23+
24+
25+ if _sentinel is None:
26+ _sentinel = posix.environ.get (b" PYTHON_CROSSENV" )
1327if _sentinel != b" {{context.sentinel}}" :
1428 print (" *******************************************************" , file= sys.stderr )
1529 print (" * Crossenv has leaked into another Python interpreter!" , file= sys.stderr )
Original file line number Diff line number Diff line change 11import os
22import re
3+ import subprocess
34from textwrap import dedent
45
56import pytest
@@ -218,6 +219,30 @@ def test_environment_leak(crossenv):
218219 ),
219220 ],
220221 universal_newlines = True ,
222+ stderr = subprocess .STDOUT ,
223+ )
224+ assert "Crossenv has leaked" not in out
225+
226+
227+ def test_environment_subinterpreter_leak (crossenv ):
228+ pytest .importorskip ("concurrent.interpreters" )
229+ out = crossenv .check_output (
230+ [
231+ "python" ,
232+ "-c" ,
233+ dedent (
234+ """\
235+ import concurrent.interpreters
236+
237+ def fn():
238+ print("ok")
239+
240+ concurrent.interpreters.create().call(fn)
241+ """
242+ ),
243+ ],
244+ universal_newlines = True ,
245+ stderr = subprocess .STDOUT ,
221246 )
222247 assert "Crossenv has leaked" not in out
223248
You can’t perform that action at this time.
0 commit comments