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

Set client_id as thread name #617

Merged
merged 1 commit into from
Dec 24, 2023
Merged

Conversation

mosauter
Copy link
Contributor

@mosauter mosauter commented Nov 3, 2021

I had a couple of problems in my code where I pulled up a couple of connections/clients and randomly it happened that in the loop an exception occurred. When it happens the exception always starts like this before the stacktrace:

Exception in thread Tread-$some_number:

... which gives not too much info where the exception happened, as the stack trace ends always at loop_forever and the interesting part would most of the time be who actually started the thread that caused the exception.

The change gives control over how the thread that is created by loop_start is named. To not change any API at all I opted for the decoded client id. If not explicitly set, there will be the usual "broker-generated string" as name, but for me that does not give any less information than the mentioned above Thread-$some_number. But if you explicitly set the client_id (which needs to be unique, so no name clashes possible as far as I can see) the thread will reflect that change, so in the exception it would print:

Exception in thread manually_set_client_id:

Copy link
Contributor

@PierreF PierreF left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank for your contribution and your patience. I've made a small suggestion change.

Also could you add a Signed-Off to your commit ? This is a requirement from Eclipse to acknowledge you agree with the ECA.

src/paho/mqtt/client.py Outdated Show resolved Hide resolved
Helps when debugging in the resulting threads as the name is shown in
the possible exception that can come up.

Signed-off-by: Moritz Sauter <sautermoritz@gmx.de>
@mosauter
Copy link
Contributor Author

Thanks for the review.

I've applied your requested change and added the sign-off.

@PierreF PierreF merged commit d1b5774 into eclipse-paho:master Dec 24, 2023
10 checks passed
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.

2 participants