Skip to content

Conversation

@matthewelwell
Copy link
Contributor

This adds the daemon argument to the EnvironmentDataPolling manager to ensure that the Flagsmith client is terminated correctly when the main thread is terminated.

I tested this using the following script:

import sys

from flagsmith import Flagsmith


if __name__ == "__main__":
    print("Creating Flagsmith client...")
    flagsmith = Flagsmith(
        environment_key="ser.HDwH8inPfcCgrNVgjiur7Z",
        enable_local_evaluation=True,
        environment_refresh_interval_seconds=5,
    )

    print("Exiting the program...")
    sys.exit()

This script previously just hung at sys.exit() because it wasn't able to kill the environment polling manager thread. Once it's changed to be created as a daemon thread, it kills it correctly and the program shuts down as expected.

The only downside to this is that the daemon thread is shutdown abruptly meaning that we might see some 'remote connection hung up' type errors in the API but I think this is not a concern.

@matthewelwell matthewelwell requested review from a team and khvn26 July 5, 2023 11:15
@matthewelwell matthewelwell merged commit 5ed3c6c into main Jul 7, 2023
@matthewelwell matthewelwell deleted the fix/environment-polling-termination branch July 7, 2023 12:27
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.

4 participants