Compile and run TestApplication.java with py4j.jar in your classpath.
Then execute python3 test.py
This creates three pairs of GatewayServer and CallbackServer with different ports on both the Java and Python sides. Python is driving the communication by asking Java to print a String. Then it calls a method that calls back a Python instance. Finally, it shuts down the Java GatewayServer. When the three GatewayServer instances are shut down, the Java and the Python programs exit.