'Run the specified code in Python (in a new child process) and read the
output from the standard error or from a file (if filename is set).
Return the output lines as a list.
Strip the reference count from the standard error for Python debug
build, and replace "Current thread 0x00007f8d8fbd9700" by "Current
thread XXX".'

def get_output(self, code, filename=None):

    code = dedent(code).strip()
    with support.SuppressCrashReport():
        process = script_helper.spawn_python('-c', code)
    (stdout, stderr) = process.communicate()
    exitcode = process.wait()
    output = support.strip_python_stderr(stdout)
    output = output.decode('ascii', 'backslashreplace')
    if filename:
        self.assertEqual(output, '')
        with open(filename, 'rb') as fp:
            output = fp.read()
        output = output.decode('ascii', 'backslashreplace')
    output = re.sub('Current    thread    0x[0-9a-f]+', 'Current    thread    XXX', output)
    return (output.splitlines(), exitcode)
