java

call_java(class_name, args=[], classpath=None)[source]
java_call_command(class_name, classpath=None)[source]

List of components for a subprocess call to Java, used by call_java

start_java_process(class_name, args=[], java_args=[], wait=0.1, classpath=None)[source]
class Py4JInterface(gateway_class, port=None, python_port=None, gateway_args=[], pipeline=None, print_stdout=True, print_stderr=True, env={}, system_properties={}, java_opts=[], timeout=10.0, prefix_classpath=None)[source]

Bases: object

If pipeline is given, configuration is looked for there. If found, this overrides config given in other kwargs.

If print_stdout=True (default), stdout from processes will be printed out to the console in addition to any other processing that’s done to it. Same with stderr. By default, both are output to the console.

env adds extra variables to the environment for running the Java process.

system_properties adds Java system property settings to the Java command.

start(timeout=None, port_output_prefix=None)[source]

Start a Py4J gateway server in the background on the given port, which will then be used for communicating with the Java app.

If a port has been given, it is assumed that the gateway accepts a –port option. Likewise with python_port and a –python-port option.

If timeout is given, it overrides any timeout given in the constructor or specified in local config.

new_client()[source]
stop()[source]
clear_output_queues()[source]
no_retry_gateway(**kwargs)[source]

A wrapper around the constructor of JavaGateway that produces a version of it that doesn’t retry on errors. The default gateway keeps retying and outputting millions of errors if the server goes down, which makes responding to interrupts horrible (as the server might die before the Python process gets the interrupt).

TODO This isn’t working: it just gets worse when I use my version!

gateway_client_to_running_server(port)[source]
launch_gateway(gateway_class='py4j.GatewayServer', args=[], javaopts=[], redirect_stdout=None, redirect_stderr=None, daemonize_redirect=True, env={}, port_output_prefix=None, startup_timeout=10.0, prefix_classpath=None)[source]

Our own more flexble version of Py4J’s launch_gateway.

get_redirect_func(redirect)[source]
class OutputConsumer(redirects, stream, *args, **kwargs)[source]

Bases: threading.Thread

Thread that consumes output Modification of Py4J’s OutputConsumer to allow multiple redirects.

remove_temporary_redirects()[source]
run()[source]

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

output_p4j_error_info(command, returncode, stdout, stderr)[source]
make_py4j_errors_safe(fn)[source]

Decorator for functions/methods that call Py4J. Py4J’s exceptions include information that gets retrieved from the Py4J server when they’re displayed. This is a problem if the server is not longer running and raises another exception, making the whole situation very confusing.

If you wrap your function with this, Py4JJavaErrors will be replaced by our own exception type Py4JSafeJavaError, containing some of the information about the Java exception if possible.

exception Py4JSafeJavaError(java_exception=None, str=None)[source]

Bases: Exception

exception DependencyCheckerError[source]

Bases: Exception

exception JavaProcessError[source]

Bases: Exception