Skip to content

Provide arguments to enable dispatcher handling of network errors#128

Open
whorfin wants to merge 1 commit intoLeggin:mainfrom
whorfin:main
Open

Provide arguments to enable dispatcher handling of network errors#128
whorfin wants to merge 1 commit intoLeggin:mainfrom
whorfin:main

Conversation

@whorfin
Copy link

@whorfin whorfin commented Feb 15, 2026

This simple patch adds dispatcher and reconnect arguments to create_event_listener()
These are passed to the WebSocketApp run_forever() method to allow recovery from network errors
See https://github.com/websocket-client/websocket-client/tree/10d9159af9ba1ecb76e0ebb6a04edfd990eacbbb?tab=readme-ov-file#long-lived-connection

I've verified that if the websocket socket is closed due to network errors (as opposed to the DIRIGERA hub inactivity close, which is a "normal" status 1000 event), without this, the dirigera create_event_listener loop will exit.
With these arguments, one can follow the method on the websocket-client README to use a dispatcher such as rel to handle this, and all is well.

ps - thank you for contributing this library, it's been immensely helpful and i deeply appreciate it

These are passed to the WebSocketApp run_forever() method to allow
recovery from network errors
@whorfin
Copy link
Author

whorfin commented Feb 16, 2026

To make this less academic, here's the sort of code I'm running now, and in testing so far it correctly reconnects both due to network problems and the "disconnected due to inactivity" issue

It's only been a few disconnect/reconnects so far, but note that i did not see the on_close() callback happen, nor did I get an on_error() - the messages were entirely from inside websocket modules

def start_listener():
    # event listener loop
    dirigera_hub.create_event_listener(
        ping_intervall = 10,    # default is 60 - will we be more responsive?
        on_message=on_message,
        on_error=on_error,
        on_close=on_close,
        dispatcher=rel, reconnect=5
    )
    # the run_forever will return; set up the rel dispatcher to do the loop
    print("Dirigera Server: listener started")
    rel.dispatch()
    print("Dirigera Server: dispatcher finished")

# start the listener, which may auto-restart
start_listener()

This may also be helpful for #113

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant