Repository navigation
BUG: Release the usage sharing element without waiting for its sending thread - #275
Merged
Merged
Conversation
…g thread When the garbage collector releases a usage sharing element that was never closed, the element now stops its sending thread without waiting for it. The collector can run on any thread, including a new thread that is starting and holds the lock a thread needs to end. Waiting there never returned, and the usage sharing tests stopped until the job's time limit. A message already going out still finishes on the sending thread, which the interpreter waits for at exit. test_share_usage_release.py checks that releasing returns while a send is held, and that the held message is sent once it is let go.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
ShareUsage.__del__inpipeline/fiftyone_pipeline_engines_fiftyone/src/fiftyone_pipeline_engines_fiftyone/share_usage.pynow callsthread_pool.shutdown(wait=False)every time. Before, it waited for the sending thread when the element had not been closed.Why
The garbage collector calls
__del__on whichever thread it happens to run on. In the release run for #240, the Python 3.10 build entries on Ubuntu and Windows stopped intests/test_usage.pyand ran until the two-hour job limit. A local run on Python 3.10.11 hung in the same way, and the stack dump showed why. A new sending thread was starting and held the lock inthreadingthat tracks running threads. The collector ran on that thread and released an earlier element that had never been closed. Its__del__then joined that element's sending thread, and the join needs that same lock, so it never returned. The test thread waited for the new thread to start, and the run stopped.Closing still sends what is queued, within its five-second bound. A message already going out when an element is released still finishes on the sending thread, and the interpreter waits for that thread at exit.
Tests
pipeline/fiftyone_pipeline_engines_fiftyone/tests/test_share_usage_release.py, with one test. It holds a send, releases the element on a thread of its own, and checks that releasing returns while the send is still held and that the message is sent once the send is let go. Before the change it failed after 30 seconds ("Releasing the element waited for the message being sent."). After the change it passes.tests/test_usage.pyon Python 3.10.11 (Windows): before the change, 1 of 6 runs hung after 35 tests. After the change, 12 of 12 runs passed, with 40 tests in each.fiftyone_pipeline_engines_fiftyonetest suite: 156 passed on Python 3.10.11 and 156 passed on Python 3.12.