Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify ScriptSession dependencies #4190

Merged
merged 3 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions engine/table/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,6 @@ plugins {

description 'Engine Table: Implementation and closely-coupled utilities'

sourceSets {
main {
resources {
srcDir 'groovy'
include 'core/*.groovy'
}
resources {
srcDir 'python'
include 'core/*.py'
}
resources {
srcDir 'src/main/resources'
include '**'
}
}
}

configurations {
// Ensure jmh picks up the same dependencies as tests
jmhImplementation.extendsFrom testImplementation
Expand Down
85 changes: 0 additions & 85 deletions engine/table/groovy/core/deephaven_core_utils.groovy

This file was deleted.

18 changes: 0 additions & 18 deletions engine/table/python/core/deephaven_jpy_init.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ private static void markReadyAndCheckEnv() {
try (
final PyModule deephavenJpyModule = PyModule.importModule("deephaven_internal.jvm");
final PyObject readyObj = deephavenJpyModule.callMethod("ready");
final PyObject checkObj = deephavenJpyModule.callMethod("check_py_env")) {
final PyObject checkObj = deephavenJpyModule.callMethod("check_py_env");
final PyObject initObj = deephavenJpyModule.callMethod("init_py")) {
// empty
}
}
Expand Down
4 changes: 2 additions & 2 deletions props/configs/src/main/resources/dh-defaults.prop
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ QueryPerformanceRecorder.packageFilter.internal=defaultPackageFilters.qpr

########## Deephaven Groovy and Python Session defaults ##########

GroovyDeephavenSession.initScripts=core/deephaven_core_utils.groovy
GroovyDeephavenSession.initScripts=

PythonDeephavenSession.initScripts=core/deephaven_jpy_init.py
PythonDeephavenSession.initScripts=

default.processEnvironmentFactory=io.deephaven.util.process.DefaultProcessEnvironment$Factory

Expand Down
4 changes: 2 additions & 2 deletions props/test-configs/src/main/resources/dh-tests.prop
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ QueryPerformanceRecorder.packageFilter.internal=defaultPackageFilters.qpr

########## Deephaven Groovy and Python Session defaults ##########

GroovyDeephavenSession.initScripts=core/deephaven_core_utils.groovy
GroovyDeephavenSession.initScripts=

PythonDeephavenSession.initScripts=core/deephaven_jpy_init.py
PythonDeephavenSession.initScripts=

###### Measurement Options ######
statsdriver.enabled=false
Expand Down
22 changes: 22 additions & 0 deletions py/server/deephaven_internal/jvm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,25 @@ def init_jvm(*args, **kwargs):
"Unable to initialize JVM, try setting the environment variable JAVA_HOME (JDK 11+ required)") from e
ready()
return result

def init_py():
"""Finishes starting Python to be usable from inside of a Java process. Not intended to be called in cases
where the process was started as Python, and Java was started from inside Python.
"""

import jpy
import os
import sys
from deephaven_internal.stream import TeeStream

# Set stdin to /dev/null to prevent functions (like help()) that attempt to read from stdin from hanging python
# execution from within Java.
os.dup2(os.open("/dev/null", os.O_RDONLY), 0)

jpy.VerboseExceptions.enabled = True
# If you want jpy to tell you about all that it is doing, change this
# jpy.diag.flags = jpy.diag.F_ALL
Comment on lines +85 to +86
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be an ENV controlled option to help us debug users?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems like a decent idea, but in a different PR (i'm just moving the contents of this file so we have one fewer way to screw up startup).


j_sys = jpy.get_type('java.lang.System')
sys.stdout = TeeStream.redirect(sys.stdout, j_sys.out)
sys.stderr = TeeStream.redirect(sys.stderr, j_sys.err)
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public enum WorkerPythonEnvironment {
.getStringWithDefault("WorkerPythonEnvironment.defaultScriptPath", ".");

final ScriptFinder scriptFinder = new ScriptFinder(defaultScriptPath);
final String initScript = Configuration.getInstance().getStringWithDefault("WorkerPythonEnvironment.initScript",
"core/deephaven_jpy_init.py");
final String initScript =
Configuration.getInstance().getStringWithDefault("WorkerPythonEnvironment.initScript", "");

final ScriptFinder.FileOrStream file;
try {
Expand Down
Loading