On This Page

Previous topic

4.5. py4j.finalizer — Py4J Finalizer API

Next topic

5. Py4J Java API

This Page

4.6. py4j.signals — Py4J Signals API

The py4j.signals module contains classes that enables the creation of signals, i.e., events that can be sent to “receivers”. A receiver must connect to a signal beforehand and can optionally specify from which sender it should receive signals.

Here is a full usage example:

# Declare a signal
server_connection_stopped = Signal()
"""Signal sent when a Python (Callback) Server connection is stopped.

Will supply the ``connection`` argument, an instance of CallbackConnection.

The sender is the CallbackServer instance.
"""

server = ...
connection = ...

# Create a receiver
def on_connection_stopped(sender, **kwargs):
    connection = kwargs["connection"]
    # ...

# Connect the receiver to the signal. Only signals sent from
# server will be sent to on_connection_stopped.
server_connection_stopped.connect(on_connection_stopped, sender=server)

# Send a signal to the receivers. If one receiver raises an error,
# the error is propagated back and other receivers won't receive the
# signal.
server_connection_stopped.send(sender=server, connection=connection)

4.6.1. Signal

Questions/Feedback?