Skip to content
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

disable multiprocessing if unavailable #39

Merged
merged 2 commits into from
Dec 3, 2015
Merged

disable multiprocessing if unavailable #39

merged 2 commits into from
Dec 3, 2015

Conversation

jsphpl
Copy link
Contributor

@jsphpl jsphpl commented Nov 5, 2015

I hacked something up, please check if you're okay with it. Couldn't get the tests running, so this code was tested only manually – not sure if these code changes require the tests to be updated.

@@ -611,7 +628,11 @@ def s3_iter_bucket(bucket, prefix='', accept_key=lambda key: True, key_limit=Non
if key_limit is not None and key_no + 1 >= key_limit:
# we were asked to output only a limited number of keys => we're done
break
pool.terminate()

try:
Copy link
Owner

Choose a reason for hiding this comment

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

Cleaner to check against NO_MULTIPROCESSING, same way as above, rather than try-catch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true

Copy link
Owner

Choose a reason for hiding this comment

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

@jsphpl Can you fix this? Then we're ready to merge (the tests we can add later). Cheers!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PR updated. But still the 2.6 tests fail due to a timeout when testing s3_iter_bucket() - any idea about that?

@piskvorky
Copy link
Owner

Thanks @jsphpl .

The py2.6 tests pass too, it was just some Travis glitch.

Can you add a test around this NO_MULTIPROCESSING functionality too though? Refactoring could easily break this later on and we'd never know.

@jsphpl
Copy link
Contributor Author

jsphpl commented Nov 6, 2015

@piskvorky i could implement it, but have no clue how to approach this. Any ideas?

  • Check if NO_MULTIPROCESSING is set, well… but how to force import multiprocessing to throw an exception?
  • How to check, that s3_iter_bucket() isn't using multiprocessing? Do we even need to, as it would fail given that multiprocessing is unavailable?

Would be great if you could point me in the right direction, as i have zero experience with mock & moto… Thanks!

@piskvorky
Copy link
Owner

Sure, no problem. I was thinking something simple:

  1. multiprocessing cannot be imported => flag NO_MULTIPROCESSING is set
  2. force the NO_MULTIPROCESSING flag and run all the existing s3_iter_bucket tests. Maybe all that needed is an outer loop, for multiprocessing_flag in [True, False]: smart_open_lib.NO_MULTIPROCESSING = multiprocessing_flag; continue with the rest of test body...). Value of True will correspond to the existing tests, False should be taking your new code branch.

@jsphpl
Copy link
Contributor Author

jsphpl commented Nov 12, 2015

Sounds good. But how, again, would you simulate the import error for multiprocessing, in order to check if the flag is set? I couldn't find anything about that in pyunit related docs, nor can i think of a creative solution to this…

@piskvorky
Copy link
Owner

I didn't even think of testing that automatically. Just test that it works for you / solves your use case.

In the unit tests, I thought we'd set the flag manually (force both True and False) and see that both code paths work.

@jsphpl
Copy link
Contributor Author

jsphpl commented Nov 16, 2015

Great, let’s do it like that…

Joseph Paul
Sent with Airmail

Am 12. November 2015 bei 13:40:52, Radim Řehůřek (notifications@github.com) schrieb:

I didn't even think of testing that.

I just thought we'd set the flag manually (True/False) and see that both code paths work.


Reply to this email directly or view it on GitHub.

piskvorky added a commit that referenced this pull request Dec 3, 2015
disable multiprocessing if unavailable
@piskvorky piskvorky merged commit 57ac71e into piskvorky:master Dec 3, 2015
@piskvorky
Copy link
Owner

Thanks for the if fix @jsphpl -- merged :)

@tmylk
Copy link
Contributor

tmylk commented Dec 16, 2015

@jsphpl Could we set the flag and test in the unit tests? (both True and False)

@tmylk tmylk mentioned this pull request Dec 18, 2015
@jsphpl
Copy link
Contributor Author

jsphpl commented Dec 18, 2015

@tmylk i'm having trouble with the test environment on my machine and don't want to push untested tests ;). So if you feel like writing the tests, please feel free! I'd be thankful if you could help! Otherwise i'll have to get the tests running…

@jsphpl jsphpl mentioned this pull request Dec 18, 2015
@tmylk
Copy link
Contributor

tmylk commented Dec 18, 2015

@jsphpl Feel free to push "untested tests". They only take 30 sec to run and Travis is free. :)

@jsphpl
Copy link
Contributor Author

jsphpl commented Dec 18, 2015

@tmylk True, i'll give it a shot.

except ImportError:
logger.warning("multiprocessing could not be imported and won't be used")
NO_MULTIPROCESSING = True
from itertools import imap
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this might break Python 3. imap is only available in Python 2.

Copy link
Owner

Choose a reason for hiding this comment

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

@tmylk how come the unit tests have been passing for a year then?

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