Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

documentation for run_in_thread with exception_handler seems to be misleading #3464

Open
mbec-lbto opened this issue Dec 21, 2024 · 0 comments

Comments

@mbec-lbto
Copy link

mbec-lbto commented Dec 21, 2024

Version: 5.0.5
but really the current online documentation https://redis-py.readthedocs.io/en/stable/advanced_features.html#publish-subscribe

Platform: Python 3.12 fedora40

Description:
The documentation for run_in_thread with exception_handler is misleading. Sample code you provide (with annotations)

p.subscribe(**{'my-channel': my_handler})
def exception_handler(ex, pubsub, thread):
    print(ex)
    thread.stop()
    thread.join(timeout=1.0) # this raises RuntimeError("cannot join current thread")
    pubsub.close() # this never gets called
thread = p.run_in_thread(exception_handler=exception_handler)

The handler runs in the context of the thread, and the thread argument is "self".
Calling join() on itself, the handler will raise RuntimeError("cannot join current thread"), and exit "uncleanly" (without closing pubsub). so it works, but it seems a bit misleading.

These might be better examples for the documentation:

def exception_handler(ex, pubsub, thread):
    print(ex)
    thread.stop()

or

def exception_handler(ex, pubsub, thread):
    print(ex)
    pubsub.close()
    raise ex
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

No branches or pull requests

1 participant