Package jep

Class SubInterpreterOptions

java.lang.Object
jep.SubInterpreterOptions

public class SubInterpreterOptions extends Object
A configuration object containing additional options for constructing a SubInterpreter. These options map directly to the options documented at https://docs.python.org/3/c-api/init.html#c.PyInterpreterConfig. These options are ignored if a Python version earlier than 3.12 is used with Jep.
Since:
4.2
  • Method Details

    • setUseMainObmalloc

      public SubInterpreterOptions setUseMainObmalloc(boolean useMainObmalloc)
      If this is false then the sub-interpreter will use its own "object" allocator state. Otherwise it will use (share) the main interpreter's. If this is false then check_multi_interp_extensions must be true. If this is true then own GIL must not be true. Shared Modules cannot be used when this is set to false.
      Parameters:
      useMainObmalloc - whether the sub-interpreter will share the main interpreter's allocator state.
      Returns:
      a reference to this SubInterpreterOptions
    • setAllowFork

      public SubInterpreterOptions setAllowFork(boolean allowFork)
      If this is false then the runtime will not support forking the process in any thread where the sub-interpreter is currently active. Otherwise fork is unrestricted. Note that the subprocess module still works when fork is disallowed.
      Parameters:
      allowFork - whether the sub-interpreter will allow fork.
      Returns:
      a reference to this SubInterpreterOptions
    • setAllowExec

      public SubInterpreterOptions setAllowExec(boolean allowExec)
      If this is false then the runtime will not support replacing the current process via exec (e.g. os.execv()) in any thread where the sub-interpreter is currently active. Otherwise exec is unrestricted. Note that the subprocess module still works when exec is disallowed.
      Parameters:
      allowExec - whether the sub-interpreter will allow exec.
      Returns:
      a reference to this SubInterpreterOptions
    • setAllowThreads

      public SubInterpreterOptions setAllowThreads(boolean allowThreads)
      If this is false then the sub-interpreter's threading module won't be able to create threads. Otherwise threads are allowed.
      Parameters:
      allowThreads - whether the sub-interpreter will allow threads.
      Returns:
      a reference to this SubInterpreterOptions
    • setAllowDaemonThreads

      public SubInterpreterOptions setAllowDaemonThreads(boolean allowDaemonThreads)
      If this is false then the sub-interpreter's threading module won't be able to create daemon threads. Otherwise daemon threads are allowed (as long as allowThreads is true).
      Parameters:
      allowDaemonThreads - whether the sub-interpreter will allow daemon threads.
      Returns:
      a reference to this SubInterpreterOptions
    • setCheckMultiInterpeExtensions

      @Deprecated public SubInterpreterOptions setCheckMultiInterpeExtensions(boolean checkMultiInterpeExtensions)
      Deprecated.
      Deprecated in Jep 4.2.1. This method is misspelled and has a typo in the name. Please use the correctly named setCheckMultiInterpExtensions(boolean). The misspelled method will be removed in Jep 4.3.
      If this is false then all extension modules may be imported, including legacy (single-phase init) modules, in any thread where the sub-interpreter is currently active. Otherwise only multi-phase init extension modules (see PEP 489) may be imported. This must be true if useMainObmalloc is false.
      Parameters:
      checkMultiInterpeExtensions - whether the sub-interpreter will restrict import of legacy modules
      Returns:
      a reference to this SubInterpreterOptions
    • setCheckMultiInterpExtensions

      public SubInterpreterOptions setCheckMultiInterpExtensions(boolean checkMultiInterpExtensions)
      If this is false then all extension modules may be imported, including legacy (single-phase init) modules, in any thread where the sub-interpreter is currently active. Otherwise only multi-phase init extension modules (see PEP 489) may be imported. This must be true if useMainObmalloc is false.
      Parameters:
      checkMultiInterpExtensions - whether the sub-interpreter will restrict import of legacy modules
      Returns:
      a reference to this SubInterpreterOptions
    • setOwnGIL

      public SubInterpreterOptions setOwnGIL(boolean ownGIL)
      This determines the operation of the GIL for the sub-interpreter. When this is false use (share) the main interpreter's GIL. When this is true use the sub-interpreter's own GIL. If this is true then useMainObmalloc must be false.
      Parameters:
      ownGIL - whether the sub-interpreter will use its own GIL.
      Returns:
      a reference to this SubInterpreterOptions
    • legacy

      public static SubInterpreterOptions legacy()
      Create a new SubInterpreterOptions with the default legacy settings. All settings can be changed using the setters in this class.
    • isolated

      public static SubInterpreterOptions isolated()
      Create a new SubInterpreterOptions with the default isolated settings. Using these settings eliminates GIL contention but may not be compatible with all third party modules. These settings are not compatible with shared modules. All settings can be changed using the setters in this class.
    • toString

      public String toString()
      Overrides:
      toString in class Object