bpo-38858: Small integer per interpreter by vstinner · Pull Request #17315 · python/cpython (original) (raw)

Example:

>>> from test import support
>>> support.run_in_subinterp("x=1; y=int(1.0); z=x+y; print(x is y, id(z) == id(2), f'x={id(x):x}, y={id(y):x}, z={id(z):x}')")
True True x=7fd037f5b780, y=7fd037f5b780, z=7fd037ffdec0
0
>>> x=1; y=int(1.0); z=x+y; print(x is y, id(z) == id(2), f'x={id(x):x}, y={id(y):x}, z={id(z):x}')
True True x=7fd038fd7280, y=7fd038fd7280, z=7fd038fd72c0

The subinterpreter and the main interpreter don't have the same small integer singletons for numbers 1 and 2.