Repository: Avaiga/taipy
File: taipy/gui/gui.py (Python)

Code before:
        Arguments:
            favicon_path: The path to the image file to use.<br/>
                This can be expressed as a path name or a URL (relative or not).
            state: The state to apply the change to.<br/>
                If no set or set to None, all the application's clients are impacted.
        """
        if state or self.__favicon != favicon_path:
            if not state:
                self.__favicon = favicon_path
            url = self._get_content("__taipy_favicon", favicon_path, True)
            self._broadcast(
                "taipy_favicon", url, self._get_client_id() if state else None, message_type=_WsType.FAVICON
            )

    @staticmethod
    def _add_event_listener(
        event_name: str,
        listener: t.Union[
            t.Callable[[str, t.Dict[str, t.Any]], None], t.Callable[[State, str, t.Dict[str, t.Any]], None]
        ],
        with_state: t.Optional[bool] = False,
    ):
        try:
            _Hooks()._add_event_listener(event_name, listener, with_state)
        except Exception as e:
            _warn("Hooks: ", e)

    def _fire_event(
        self, event_name: str, client_id: t.Optional[str] = None, payload: t.Optional[t.Dict[str, t.Any]] = None
    ):
        Timer(interval=0.1,
            function=self.__do_fire_event,
            args=(event_name, client_id, payload),
        ).start()

    def __do_fire_event(
        self, event_name: str, client_id: t.Optional[str] = None, payload: t.Optional[t.Dict[str, t.Any]] = None
    ):
        this_sid = None
        if request:
            # avoid messing with the client_id => Set(ws id)
            this_sid = getattr(request, "sid", None)
            request.sid = None  # type: ignore[attr-defined]

        try:
            with self.get_flask_app().app_context():
                if client_id:
                    setattr(g, Gui.__ARG_CLIENT_ID, client_id)
                _Hooks()._fire_event(event_name, client_id, payload)
        except Exception as e:
            _warn("Hooks: ", e)

Review comment (suggestion):
```suggestion
            _warn("Exception in Hook._add_event_listener(): ", e)
```

Code after:
        listener: t.Union[
            t.Callable[[str, t.Dict[str, t.Any]], None], t.Callable[[State, str, t.Dict[str, t.Any]], None]
        ],
        with_state: t.Optional[bool] = False,
    ):
        _Hooks()._add_event_listener(event_name, listener, with_state)

    def _fire_event(
        self, event_name: str, client_id: t.Optional[str] = None, payload: t.Optional[t.Dict[str, t.Any]] = None
    ):
        # the event manager will take care of starting the thread
        # once the current callback (or the next one) is finished
        self.__event_manager._add_thread(
            Thread(
                target=self.__do_fire_event,
                args=(event_name, client_id, payload),
            )
        )

    def __do_fire_event(
        self, event_name: str, client_id: t.Optional[str] = None, payload: t.Optional[t.Dict[str, t.Any]] = None
    ):
        this_sid = None
        if request:
            # avoid messing with the client_id => Set(ws id)
            this_sid = getattr(request, "sid", None)
            request.sid = None  # type: ignore[attr-defined]

        try:
            with self.get_flask_app().app_context(), self.__event_manager:
                if client_id:
                    setattr(g, Gui.__ARG_CLIENT_ID, client_id)
                _Hooks()._fire_event(event_name, client_id, payload)
        finally:
            if this_sid:
                request.sid = this_sid  # type: ignore[attr-defined]