Package io.deephaven.integrations.python
Class PythonDeephavenSession
java.lang.Object
io.deephaven.util.referencecounting.ReferenceCounted
io.deephaven.engine.liveness.ReferenceCountedLivenessReferent
io.deephaven.engine.liveness.ReferenceCountedLivenessNode
io.deephaven.engine.liveness.LivenessArtifact
io.deephaven.engine.util.AbstractScriptSession<PythonDeephavenSession.PythonSnapshot>
io.deephaven.integrations.python.PythonDeephavenSession
- All Implemented Interfaces:
LogOutputAppendable
,LivenessManager
,LivenessNode
,LivenessReferent
,ScriptSession
,Serializable
public class PythonDeephavenSession
extends AbstractScriptSession<PythonDeephavenSession.PythonSnapshot>
A ScriptSession that uses a JPy cpython interpreter internally.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class io.deephaven.engine.util.AbstractScriptSession
AbstractScriptSession.ScriptSessionQueryScope, AbstractScriptSession.Snapshot
Nested classes/interfaces inherited from interface io.deephaven.engine.util.ScriptSession
ScriptSession.Changes, ScriptSession.Listener
-
Field Summary
Fields inherited from class io.deephaven.engine.util.AbstractScriptSession
classCacheDirectory, executionContext
-
Constructor Summary
ConstructorDescriptionPythonDeephavenSession
(UpdateGraph updateGraph, OperationInitializer operationInitializer, ThreadInitializationFactory threadInitializationFactory, PythonScope<?> scope) Creates a Python "ScriptSession
", for use where we should only be reading from the scope, such as an IPython kernel session.PythonDeephavenSession
(UpdateGraph updateGraph, OperationInitializer operationInitializer, ThreadInitializationFactory threadInitializationFactory, ObjectTypeLookup objectTypeLookup, @Nullable ScriptSession.Listener listener, boolean runInitScripts, PythonEvaluatorJpy pythonEvaluator) Create a Python ScriptSession. -
Method Summary
Modifier and TypeMethodDescriptionprotected ScriptSession.Changes
createDiff
(PythonDeephavenSession.PythonSnapshot from, PythonDeephavenSession.PythonSnapshot to, RuntimeException e) protected PythonDeephavenSession.PythonSnapshot
protected void
Evaluates command in the context of the current ScriptSession.getAllValues
(@Nullable Function<Object, T> valueMapper, QueryScope.ParamFilter<T> filter) Returns a mutable map with all known variables and their values.protected <T> T
getVariable
(String name) Retrieve a variable from the script session's bindings.Retrieves all variable names present in the session's scope.protected boolean
hasVariable
(String name) Check if the scope has the given variable name.void
popScope()
void
pushScope
(org.jpy.PyObject pydict) protected Object
setVariable
(String name, @Nullable Object newValue) Inserts a value into the script's scope.protected PythonDeephavenSession.PythonSnapshot
unwrapObject
(@Nullable Object object) Asks the session to remove any wrapping that exists on scoped objects so that clients can fetch them.Methods inherited from class io.deephaven.engine.util.AbstractScriptSession
applyVariableChangeToDiff, createScriptCache, destroy, evaluateScript, evaluateScript, getExecutionContext, getQueryScope, newClassCacheLocation, observeScopeChanges, publishInitial
Methods inherited from class io.deephaven.engine.liveness.LivenessArtifact
manageWithCurrentScope
Methods inherited from class io.deephaven.engine.liveness.ReferenceCountedLivenessNode
getWeakReference, initializeTransientFieldsForLiveness, onReferenceCountAtZero, tryManage, tryUnmanage, tryUnmanage
Methods inherited from class io.deephaven.engine.liveness.ReferenceCountedLivenessReferent
dropReference, tryRetainReference
Methods inherited from class io.deephaven.util.referencecounting.ReferenceCounted
append, decrementReferenceCount, forceReferenceCountToZero, getReferenceCountDebug, incrementReferenceCount, resetReferenceCount, toString, tryDecrementReferenceCount, tryIncrementReferenceCount
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.deephaven.engine.liveness.LivenessManager
manage, tryManage, tryUnmanage, tryUnmanage, unmanage, unmanage
Methods inherited from interface io.deephaven.engine.liveness.LivenessReferent
dropReference, getReferentDescription, getWeakReference, retainReference, tryRetainReference
Methods inherited from interface io.deephaven.engine.util.ScriptSession
evaluateScript, sanitizeThrowable
-
Field Details
-
SCRIPT_TYPE
-
-
Constructor Details
-
PythonDeephavenSession
public PythonDeephavenSession(UpdateGraph updateGraph, OperationInitializer operationInitializer, ThreadInitializationFactory threadInitializationFactory, ObjectTypeLookup objectTypeLookup, @Nullable @Nullable ScriptSession.Listener listener, boolean runInitScripts, PythonEvaluatorJpy pythonEvaluator) throws IOException Create a Python ScriptSession.Sets the configuration property "python.version" to the value returned from the python code
platform.python_version()
.- Parameters:
updateGraph
- the default update graph to install for the reploperationInitializer
- the default operation initializer to install for the replobjectTypeLookup
- the object type lookuplistener
- an optional listener that will be notified whenever the query scope changesrunInitScripts
- if init scripts should be executedpythonEvaluator
-- Throws:
IOException
- if an IO error occurs running initialization scripts
-
PythonDeephavenSession
public PythonDeephavenSession(UpdateGraph updateGraph, OperationInitializer operationInitializer, ThreadInitializationFactory threadInitializationFactory, PythonScope<?> scope) Creates a Python "ScriptSession
", for use where we should only be reading from the scope, such as an IPython kernel session.
-
-
Method Details
-
getVariable
Description copied from class:AbstractScriptSession
Retrieve a variable from the script session's bindings. Values may need to be unwrapped.- Specified by:
getVariable
in classAbstractScriptSession<PythonDeephavenSession.PythonSnapshot>
- Parameters:
name
- the name of the variable to retrieve- Returns:
- the variable value
- Throws:
QueryScope.MissingVariableException
- if the variable does not exist
-
pushScope
-
popScope
-
evaluate
Description copied from class:AbstractScriptSession
Evaluates command in the context of the current ScriptSession.- Specified by:
evaluate
in classAbstractScriptSession<PythonDeephavenSession.PythonSnapshot>
- Parameters:
command
- the command to evaluatescriptName
- an optional script name, which may be ignored by the implementation, or used improve error messages or for other internal purposes
-
emptySnapshot
- Specified by:
emptySnapshot
in classAbstractScriptSession<PythonDeephavenSession.PythonSnapshot>
-
takeSnapshot
- Specified by:
takeSnapshot
in classAbstractScriptSession<PythonDeephavenSession.PythonSnapshot>
-
createDiff
protected ScriptSession.Changes createDiff(PythonDeephavenSession.PythonSnapshot from, PythonDeephavenSession.PythonSnapshot to, RuntimeException e) - Specified by:
createDiff
in classAbstractScriptSession<PythonDeephavenSession.PythonSnapshot>
-
getVariableNames
Description copied from class:AbstractScriptSession
Retrieves all variable names present in the session's scope.- Specified by:
getVariableNames
in classAbstractScriptSession<PythonDeephavenSession.PythonSnapshot>
- Returns:
- a caller-owned mutable set of variable names
-
hasVariable
Description copied from class:AbstractScriptSession
Check if the scope has the given variable name.- Specified by:
hasVariable
in classAbstractScriptSession<PythonDeephavenSession.PythonSnapshot>
- Parameters:
name
- the variable name- Returns:
- True iff the scope has the given variable name
-
setVariable
Description copied from class:AbstractScriptSession
Inserts a value into the script's scope.- Specified by:
setVariable
in classAbstractScriptSession<PythonDeephavenSession.PythonSnapshot>
- Parameters:
name
- the variable name to setnewValue
- the new value of the variable- Returns:
- the old value for this name, if any. As with
AbstractScriptSession.getVariable(String)
, may need to be unwrapped.
-
getAllValues
protected <T> Map<String,T> getAllValues(@Nullable @Nullable Function<Object, T> valueMapper, @NotNull QueryScope.ParamFilter<T> filter) Description copied from class:AbstractScriptSession
Returns a mutable map with all known variables and their values.Callers may want to pass in a valueMapper of
ScriptSession.unwrapObject(Object)
which would unwrap values before filtering. The returned map is owned by the caller.- Specified by:
getAllValues
in classAbstractScriptSession<PythonDeephavenSession.PythonSnapshot>
- Type Parameters:
T
- the type of the mapped values- Parameters:
valueMapper
- a function to map the valuesfilter
- a predicate to filter the map entries- Returns:
- a caller-owned mutable map with all known variables and their mapped values. As with
AbstractScriptSession.getVariable(String)
, values may need to be unwrapped.
-
scriptType
- Returns:
- a textual description of this script session's language for use in messages.
-
unwrapObject
Description copied from interface:ScriptSession
Asks the session to remove any wrapping that exists on scoped objects so that clients can fetch them. Defaults to returning the object itself.- Parameters:
object
- the scoped object- Returns:
- an obj which can be consumed by a client
-