Skip to content

[Feature][Python] Implement EventListener in python sdk#688

Open
twosom wants to merge 13 commits into
apache:mainfrom
twosom:implementation-python-event-listener
Open

[Feature][Python] Implement EventListener in python sdk#688
twosom wants to merge 13 commits into
apache:mainfrom
twosom:implementation-python-event-listener

Conversation

@twosom
Copy link
Copy Markdown
Contributor

@twosom twosom commented May 18, 2026

Linked issue: #687

Purpose of change

This PR implements the EventListener mechanism for both Java and Python runtimes, ensuring API consistency across different language SDKs. It enables developers to monitor and react to events synchronously during the agent's event lifecycle.

Tests

ok

API

Documentation

  • doc-needed
  • doc-not-needed
  • doc-included

@github-actions github-actions Bot added doc-included Your PR already contains the necessary documentation updates. fixVersion/0.3.0 The feature or bug should be implemented/fixed in the 0.3.0 version. priority/major Default priority of the PR or issue. labels May 18, 2026
twosom added 13 commits May 21, 2026 09:17
…er utilities

# Conflicts:
#	api/src/main/java/org/apache/flink/agents/api/resource/python/PythonResourceAdapter.java
#	runtime/src/main/java/org/apache/flink/agents/runtime/python/utils/PythonResourceAdapterImpl.java
#	runtime/src/test/java/org/apache/flink/agents/runtime/ResourceCacheTest.java
- Move event conversion to a public method 'convertJsonToPythonEvent' for listener support
- Optimize performance by reusing a static ObjectMapper instance
- Clean up redundant ObjectMapper instantiations
- Implement PythonEventListenerWrapper in PythonBridgeManager to bridge events to Python
- Add logic to initialize and register Python listeners in ActionExecutionOperator
- Optimize Java-to-Python event conversion by performing it once per event notification
@twosom twosom force-pushed the implementation-python-event-listener branch from fa2cb94 to 680c866 Compare May 21, 2026 00:21
@wenjin272
Copy link
Copy Markdown
Collaborator

Hi, @twosom. Thanks for supporting EventListener in python sdk.

Overall, I think the current design has become somewhat overly complex. In my view, we should have a single PythonEventListenerWrapper that, at runtime, uses pemja to instantiate the corresponding Python EventListener object and simply invokes its on_event method.

I think some of the current complexity stems from supporting str(MyPythonListener). Could we use a standard Python fully-qualified class name ("my_module.MyPythonListener") as the listener identifier, instead of the str(MyPythonListener)"module:qualname.method_name" protocol?

That would let us drop EventListenerMeta, _resolve_module, the <locals> / __main__ / sys.modules fallbacks, and the matching split(":") on the Java side — Python-side instantiation collapses to importlib.import_module + getattr + rpartition(".").

The cost is that listeners must live at module top level (which the PR already enforces against <locals>) and can't be defined in __main__.

Additionally, I believe there is no need to support event listeners in the local_runner. In fact, we are also considering whether the local_runner still needs to exist

Additionally, I believe the current testing is insufficient. We have some unit tests, but no end-to-end tests. For this cross-language scenario, we need to add real tests that submit jobs to the remote environment in e2e_tests_resource_cross_language.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-included Your PR already contains the necessary documentation updates. fixVersion/0.3.0 The feature or bug should be implemented/fixed in the 0.3.0 version. priority/major Default priority of the PR or issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants