py4j.clientserver
— Py4J Single Threading Model Implementation¶The py4j.clientserver
module defines an implementation of Python Server
and Java client that ensures that commands started from a Python or Java thread
are always executed on the same Java or Python thread.
For example, if a command to Python is sent from Java UI thread and the Python code calls some Java code, the Java code will be executed in the UI thread.
Py4J users are expected to only use explicitly ClientServer
and optionally, JavaParameters
and PythonParameters
. The other module members are documented
to support the extension of Py4J.
Using the jvm
property:
>>> clientserver = ClientServer()
>>> l = clientserver.jvm.java.util.ArrayList()
>>> l.append(10)
>>> l.append(1)
>>> jvm.java.util.Collections.sort(l)
>>> l
[1, 10]
The ClientServer
class is a subclass
of JavaGateway
is fully compatible
with all examples and code written for a JavaGateway.`