-
Notifications
You must be signed in to change notification settings - Fork 97
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
asyncmapper: shutdown producer on generator close #597
Merged
Conversation
This file contains 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
Deploying datachain-documentation with Cloudflare Pages
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## issue-40 #597 +/- ##
============================================
+ Coverage 87.89% 88.00% +0.10%
============================================
Files 100 100
Lines 10041 10052 +11
Branches 1365 1367 +2
============================================
+ Hits 8826 8846 +20
+ Misses 871 865 -6
+ Partials 344 341 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
mattseddon
approved these changes
Nov 14, 2024
ilongin
approved these changes
Nov 14, 2024
skshetry
added a commit
that referenced
this pull request
Nov 20, 2024
skshetry
added a commit
that referenced
this pull request
Nov 20, 2024
* Use threading in AsyncMapper.produce() * Implement prefetching in .gen() and .map() * Avoid user code error in name_len() * asyncmapper: shutdown producer on generator close (#597) --------- Co-authored-by: skshetry <18718008+skshetry@users.noreply.github.com>
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.
Fixes the hanging issue when trying to cancel or close the script.
The test on #521 hangs. This is because we run the producer on a separate
ThreadPoolExecutor
in a loop.datachain/src/datachain/asyn.py
Lines 64 to 70 in 9fd3155
datachain/src/datachain/asyn.py
Lines 165 to 166 in 9fd3155
When the interpreter shuts down,
ThreadPoolExecutor
waits for all threads tojoin()
. Sinceproduce()
is still running,join()
hangs indefinitely.Test Failure Analysis
Although the script hangs on other platforms too, you might notice that the CI failed only on the Windows tests on #521.
This is because
test_query_e2e
sends multipleSIGINT
signals (orCTRL_C
on Windows). On the firstSIGINT
, Python raises aKeyboardInterrupt
and tries to exit, but it gets blocked bythread.join()
. On the nextSIGINT
,join()
raises an exception and exits.The latter only happens on non-Windows platform, while Windows would hang indefinitely on
thread.join()
due to:Before this PR, on non-Windows platform, it would take 2
SIGINT
signals to terminate the script.Solution
This PR adjusts
produce()
loop to check for a "shutdown" signal, and sets the signal on exit (either on success or failure).produce()
also queues items into thework_queue
, so that might hang if the queue is full. To solve that, we also drain items from the queue, so that it notices the "shutdown" signal quickly.