Thanks for this framing. Our underlying motivation has been too improve sharing between sub-interpreters. In developing that work, we felt that the deep immutability concept was interesting in its own right, and should be considered in its own right as a potential feature for Python.
We believed that providing an intermediate proposal would allow us to deliver value to Python earlier. But in doing so, we have not made as clear as we should have the underlying difficult runtime constraints on sharing objects between sub-interpreters.
Focussing on just deep immutability has also been extremely useful as we have gained a massive amount of feedback from all of you about where deep immutability would and would not be useful. We are still digesting all of that feedback, and will be updating the PEP to reflect it.
This is a great suggestion. We have a lot of material and work on the next step, so we could do this. Our concern was that would be a very large PEP, and we wanted to get something out that was smaller and more focused. But based on the feedback we have received, it seems that this is a more useful framing.
which I believe is referring to
In the sub-interpreters work, this would not consistute a data-race, as the import
would get the interpreter local version of the sys
module state. However, in the free-threaded world then this would allow a frozen function object to mutate the state of the sys
module, and potentially data-race.
I think overall, moving more things towards being interpreter/thread local is a good idea to reduce the issues around data-races. If the caching in various modules/types was moved to be interpreter/thread local, then there wouldnât be data-races.
As @steve.dower pointed out:
Sub-interpreters allow us to gradually enable more things to be safely shared. Our initial aim would be to be able to pass immutable JSon like data between sub-interpreters to allow more efficient messaging than currently exists.
Based on the feedback we have received, we will
- move to a completely opt-in model (we have gradually been moving towards this, and this discussion has helped us to clarify that this is the right approach)
- failure to freeze will be completely backtracked, so that objects can add attributes of unfreezable types, and then not become frozen. Hence, the sys module would have an attribute of an unfreezable type, and you would never be able to freeze the sys module.
- actively consider expanding the scope of the PEP to include the sub-interpreter work, and we would really appreciate feedback on this as an option from the community.