ninia / jep

Embed Python in Java
Other
1.3k stars 147 forks source link

SharedInterpreters now share MemoryManager and java PyObjects. #421

Closed bsteffensmeier closed 1 year ago

bsteffensmeier commented 2 years ago

This enables all SharedInterpreters to use the same MemoryManager so that a PyPointer from any SharedInterpreter can be used on threads from any other SharedInterpreters. This requires internal changes to MemoryManager and the way it interacts with PyPointer because there is no longer a one-to-one relationship between a tstate and a MemoryManager, instead the same MemoryManager is valid for multiple tstates.

This should introduce more flexibility for developers. For ThreadPools performing the same task in different interpreters being able to reuse PyObjects should make them a more appealing feature.

I am hoping to expand this feature in a future release so that the MainInterpreter can clean up references from the shared MemoryManager, which would remove the requirement to keep an interpreter open by allowing cleanup without another Interpreter.