bartdag/py4j — pull request #105 by JoshRosen (2012-07-29 03:38:00+00:00)
Title: Add method to launch Java GatewayServer from Python

I mainly use Py4J to call Java libraries from Python, so the Java code that creates the `GatewayServer` is pretty minimal. Generally, my Python application and Java GatewayServer have the same lifecycle.

In the past, I wrote a [small module for launching a gateway](https://github.com/JoshRosen/cmps140_creative_cooking_assistant/tree/master/py4j_server) in order to interface with [SimpleNLG](https://github.com/JoshRosen/cmps140_creative_cooking_assistant/blob/master/nlg/simplenlg.py) and the [Stanford Parser](https://github.com/JoshRosen/cmps140_creative_cooking_assistant/blob/master/nlu/nluserver.py).

It seems like this is a common use case, so I created this branch to integrate this functionality into Py4J itself.

This branch adds a `launch_gateway()` classmethod to `JavaGateway` that allows users to launch a generic Java GatewayServer from Python and obtain a `JavaGateway` instance that is connected to it. Users can override the default settings to launch the server on a non-emphermal port, add files to the server's classpath, or pass additional options to `java` (to increase the heap size, for example). The Java process is configured to die when its creator exits or is killed.

The launcher uses `sys.path` and Py4J's version number to determine the default location of the Py4J jar file, so this should work out of the box for most users (there is a `jarfile` option to explicitly specify the jar's location).

Is this a good approach? Is there a better location to place this code or an easier way to deploy Py4J for simple applications?