pimlico.core.external.java module

exception pimlico.core.external.java.DependencyCheckerError[source]

Bases: exceptions.Exception

exception pimlico.core.external.java.JavaProcessError[source]

Bases: exceptions.Exception

exception pimlico.core.external.java.Py4JSafeJavaError(java_exception=None, str=None)[source]

Bases: exceptions.Exception

class pimlico.core.external.java.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]
class pimlico.core.external.java.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

clear_output_queues()[source]
new_client()[source]
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.

stop()[source]
pimlico.core.external.java.call_java(class_name, args=[], classpath=None)[source]
pimlico.core.external.java.gateway_client_to_running_server(port)[source]
pimlico.core.external.java.get_redirect_func(redirect)[source]
pimlico.core.external.java.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.

pimlico.core.external.java.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.

pimlico.core.external.java.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!

pimlico.core.external.java.output_p4j_error_info(command, returncode, stdout, stderr)[source]
pimlico.core.external.java.start_java_process(class_name, args=[], java_args=[], wait=0.1, classpath=None)[source]