-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
customizable callback when download completed #127
Conversation
On a higher level, I am wondering what the advantage to this pattern vs inspecting the returned |
Thank you for asking! Inspecting the Results object is only possible if it runs until the expection – so all downloads need to be fully processed. If the process is killed meanwhile, that won't happen. But it's your call if you find it useful enough. If you do, I'll make the changes you requested – I agree with them :) |
That's a fair point, and I guess in an async use case you might end up wanting to do some kind of work after each file is downloaded. I would be happy to add this. I would want to understand and test what happens to the callback if the download is cancelled part way through. Do we always execute the callback or do we cancel that as well? |
Well, we should think about how we want to design it. Currently, I implemented it that the callback is always called – and in case the download was cancelled we call the callback with the Error. Then you have the flexibility when you implement the callback, to just ignore the error cases, or handle them (do cleanup etc.). |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #127 +/- ##
==========================================
+ Coverage 90.23% 90.54% +0.30%
==========================================
Files 5 5
Lines 635 645 +10
==========================================
+ Hits 573 584 +11
+ Misses 62 61 -1 ☔ View full report in Codecov by Sentry. |
I think we probably want the callbacks to execute even as we are cleaning up the call stack. No idea how we go about testing that though. |
for more information, see https://pre-commit.ci
@Cadair I added a test for the callback, I use Python 3.11 and locally it works fine – also in your test suite. I don't understand the error that's thrown for py38-conda (why does it work fine for py38?). Would you be so kind as to have a look? I also think the callback should be called when cleaning up the call stack… but yes, I also don't know how to test this. |
I have a couple of busy weeks of work coming up but I will try and get back to this soon. |
@Cadair there doesn't seem to exist a simple way to raise an exception after calling a function? |
I am not sure I follow what you are asking, where do you want to raise the exception? |
This test: https://github.com/Cadair/parfive/blob/main/parfive/tests/test_downloader.py#L324 and specifically the fixture it uses: https://github.com/Cadair/parfive/blob/main/parfive/conftest.py#L9 is rigged up to throw an error every second download. You should be able to reuse that to test that your callback gets passed an exception if a download fails. |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
@Cadair Thank you! Added the test. Do you have any idea why the build is not working? |
The publish build is failing because of an unrelated Python 3.12 issue. |
I guess then this is ready to be merged? :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for coming back to this, I think it's very close.
I think using a nonlocal
scoped variable will be nicer than the file, if that doesn't work and you need to use a temp file, please put it in tmpdir
so it doesn't clutter up the root directory.
Co-authored-by: Stuart Mumford <stuart@cadair.com>
Co-authored-by: Stuart Mumford <stuart@cadair.com>
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
nonlocal didn't work, so I went with temp files |
@Cadair would you be down for merging it? |
Thanks a lot @dreamflasher 😄 |
Closes #123