Skip to content

How to stop loop_forever() from a callback? #907

Description

@dakhnod

I have some code that sets up MQTT and runs loop_forever() in order to start the MQTT loop.

Now, I want to terminate that call from a callback like on_publish. As such, I have two questions:

  1. Is there a better pattern to just publish a message and exit than running loop_forever? I would like to avoid starting another thread using loop_start
  2. Currently, I am doing connection._thread_terminate = True, which is a hack, really. Is there a better way to stop the loop?

Thanks a lot!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: AvailableNo one has claimed responsibility for resolving this issue.

    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