Evaluate New Interpreter and Zstandard APIs
Core idea
Python 3.14 exposes multiple interpreters through concurrent.interpreters and adds Zstandard compression via compression.zstd. Interpreters have largely isolated state inside the same process, not a security boundary. Creating another interpreter does not itself schedule parallel execution; explicit threads or InterpreterPoolExecutor are needed for parallel work. Zstandard is a lossless compression format, not encryption. Both examples require 3.14 with the relevant build support.
from concurrent import interpretersworker = interpreters.create()try: worker.exec('answer = 7') worker.exec('assert answer == 7') print('executed')finally: worker.close()The fixed trusted code runs in the separate interpreter’s own main namespace. close releases it after the calls finish. No concurrency or security isolation is measured.
Documented expected output (target runtime not tested locally):
executedTarget: Python 3.14 lossless byte round-trip
from compression import zstdoriginal = b'parcel=7;' * 12compressed = zstd.compress(original)print(zstd.decompress(compressed) == original)The round-trip restores the original bytes; the compressed length is not asserted.
Documented expected output (target runtime not tested locally):
TrueCommon mistake
Do not use interpreters to isolate malicious code. Verify C-extension compatibility and data-sharing contracts; do not assume all Python objects transfer directly. For untrusted compressed input, use bounded streaming and enforce decoded-size limits instead of unrestricted one-shot decompression.
Practice
Run both fixtures on a 3.14 build supporting the modules. Record the interpreter implementation and version, and test cleanup after a fixed intentional exception. Compare the zstd result with the older zlib round-trip; do not compare speed without a benchmark.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Multiple interpreters and compression.zstd
Check your understanding of multiple interpreters and compression.zstd.
On Python 3.14 (documented expectation; target runtime not tested locally), what is printed?
from compression import zstdprint(zstd.decompress(zstd.compress(b'abc')) == b'abc')What is printed?
import zlibprint(zlib.decompress(zlib.compress(b'abc')) == b'abc')Does creating another interpreter itself start a worker thread?
What is necessary for untrusted compressed input?