- All Implemented Interfaces:
- java.lang.AutoCloseable
public class SharedInterpreter
extends Jep
Class for creating instances of Jep which do not use sub-interpreters.
Typically each Jep instance creates a unique Python sub-interpreter.
Sub-interpreters isolate different Jep instances, allowing them to be used
safely from multiple unrelated pieces of a Java application without any risk
that the Jep instances will impact each other.
This class allows creation of a Jep instance that does not use
sub-interpreters. In this case each SharedInterpreter still maintains
distinct global variables but some interpreter state will be shared. The
primary impact is that SharedInterpreters will share any imported modules.
This is equivalent to using shared modules to share every python package in
Jep. Anything that changes the way a module behaves will impact all
SharedInterpreters so care must be taken to ensure that different
SharedInterpreters aren't conflicting. For example sys.path, time.tzset(),
and numpy.seterr() will change the behavior of all SharedInterpreters.
Within a single Java process it is valid to mix Jep instances that use
sub-interpreters with SharedInterpreters. The sub-interpreter instances of
Jep will remain isolated from other Jep instances and from any
SharedInterpreters. To maintain stability, it is not possible to have
multiple Jep instances active on the same Thread at the same time and this
limitation includes SharedInterpreters.
- Since:
- 3.8