Skip to content

BUG- Event Consumer example #1344

Description

@enarroied

Hi!

The documentation about Events has a few issues: https://docs.taipy.io/en/latest/refmans/reference/pkg_taipy/pkg_event/EventProcessor/#taipy.event.EventProcessor--__tabbed_1_1

  1. First of all, the way the classes are imported. Either the docs are wrong, or there's an issue with making the imports easier in the code (maybe some imports missing in an __init__.py file?). Currently, Taipy allows importing Event and other classes like this, instead of directly from taipy as shown in the examples:
from taipy.event.event_processor import Event, EventEntityType, EventProcessor, Gui
  1. The event_received function has the arguments reversed in the "One callback to match all events" example:
def event_received(gui: Gui, event: Event):
    print(f"Received event created at : {event.creation_date}")

But it should be like this:

def event_received(event: Event, gui: Gui):
    print(f"Received event created at : {event.creation_date}")

By the way, this is documented (properly) in the on_event API doc - callable section: https://docs.taipy.io/en/latest/refmans/reference/pkg_taipy/pkg_event/EventProcessor/#taipy.event.EventProcessor.on_event

  1. This is not a bug, but I think the examples would benefit from having some Orchestrator() running to see the Event handling in action.

refactored example

For example, for the first tab, "One callback to match all events", I'd fix the three issues like this:

import taipy as tp
from taipy import Config, Orchestrator
from taipy.event.event_processor import Event, EventEntityType, EventProcessor, Gui


def do_nothing():
    print("nothing much")
    pass


nothing_task = Config.configure_task(
    "predict",
    do_nothing,
)
scenario_cfg = Config.configure_scenario("my_scenario", [nothing_task])

# def event_received(event: Event): #<-- This works too, we didn't run any Gui in this app!
def event_received(event: Event, gui: Gui):
    print(f"Received event created at {event.creation_date}")


if __name__ == "__main__":
    Orchestrator().run()
    event_processor = EventProcessor()
    event_processor.on_event(callback=event_received)
    event_processor.start()
    scenario = tp.create_scenario(scenario_cfg, name="my_scenario")
    tp.submit(scenario)

I don't have tons of time right now, but if you want, I can help some with this issue in a not too far future!

PS: The event handler also works without any gui argument

Metadata

Metadata

Assignees

No one assigned

    Labels

    💥MalfunctionAddresses an identified problem.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions