def test_undecodable_env(self):
for key, value in (('test', 'abc\uDCFF'), ('test\uDCFF', '42')):
- value_repr = repr(value).encode("ascii")
+ value_repr = ascii(value).encode("ascii")
# test str with surrogates
- script = "import os; print(repr(os.getenv(%s)))" % repr(key)
+ script = "import os; print(ascii(os.getenv(%s)))" % repr(key)
env = os.environ.copy()
env[key] = value
+ # Force surrogate-escaping of \xFF in the child process;
+ # otherwise it can be decoded as-is if the default locale
+ # is latin-1.
+ env['PYTHONFSENCODING'] = 'ascii'
stdout = subprocess.check_output(
[sys.executable, "-c", script],
env=env)
# test bytes
key = key.encode("ascii", "surrogateescape")
value = value.encode("ascii", "surrogateescape")
- script = "import os; print(repr(os.getenv(%s)))" % repr(key)
+ script = "import os; print(ascii(os.getenv(%s)))" % repr(key)
env = os.environ.copy()
env[key] = value
stdout = subprocess.check_output(
# Issue1733757
# Avoid a deadlock when sys.settrace steps into threading._shutdown
import subprocess
- rc = subprocess.call([sys.executable, "-c", """if 1:
+ p = subprocess.Popen([sys.executable, "-c", """if 1:
import sys, threading
# A deadlock-killer, to prevent the
return func
sys.settrace(func)
- """])
+ """],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ stdout, stderr = p.communicate()
+ rc = p.returncode
self.assertFalse(rc == 2, "interpreted was blocked")
- self.assertTrue(rc == 0, "Unexpected error")
+ self.assertTrue(rc == 0,
+ "Unexpected error: " + ascii(stderr))
def test_join_nondaemon_on_shutdown(self):
# Issue 1722344