Skip to content

Conversation

@shawkinsmezmo
Copy link
Contributor

Convert the flush thread from a threading.Timer to a regular threading.Thread with daemon=True. Daemon threads don't prevent the application from gracefully shutting down.

A thread can be flagged as a “daemon thread”. The significance of this flag is that the entire Python program exits when only daemon threads are left. The initial value is inherited from the creating thread. The flag can be set through the daemon property or the daemon constructor argument.

@shawkinsmezmo shawkinsmezmo requested a review from a team July 19, 2023 22:16
@shawkinsmezmo shawkinsmezmo self-assigned this Jul 19, 2023
@shawkinsmezmo shawkinsmezmo force-pushed the usr/shawkins/address-logger-shutdown-hang branch from f050135 to 818cbe2 Compare July 19, 2023 22:20
Copy link
Contributor

@dkhokhlov dkhokhlov left a comment

Choose a reason for hiding this comment

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

the main change looks ok.

I just noticed this runtime error handling may block for long time doing request retries even with should_block=False:
https://github.com/logdna/python/pull/102/files#diff-d98932f491dbf58581e648d2178063e919d9c1c80b58afa5e47bdc88c25211caR137

harmless?

@shawkinsmezmo
Copy link
Contributor Author

the main change looks ok.

I just noticed this runtime error handling may block for long time doing request retries even with should_block=False: https://github.com/logdna/python/pull/102/files#diff-d98932f491dbf58581e648d2178063e919d9c1c80b58afa5e47bdc88c25211caR137

harmless?

Should be harmless, yes. The only situation in which a RuntimeException would be thrown when attempting to submit the flush request to the thread pool would be if the pool was already shutdown, which can only happen during close, in which case there is already a final flush request that is queued up as part of the close workflow. Beyond that, the thread pool is only shut down after it is guaranteed that there is no more data actively being buffered, and all flush requests that are pending / created have completed.

Copy link
Contributor

@dkhokhlov dkhokhlov left a comment

Choose a reason for hiding this comment

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

lgtm

@shawkinsmezmo shawkinsmezmo merged commit 17a69b0 into master Jul 21, 2023
@shawkinsmezmo shawkinsmezmo deleted the usr/shawkins/address-logger-shutdown-hang branch July 21, 2023 05:33
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.

3 participants