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

Fix tests for multi-processing with spawn method (i.e. macOSX with Python>3.8) #1003

Merged
merged 2 commits into from
Feb 18, 2021

Conversation

bvreede
Copy link
Contributor

@bvreede bvreede commented Feb 12, 2021

Description

Fixed a test that caused problems with MacOSX when using multiprocessing set to spawn (standard in Python 3.8).


Before you get started

Checklist

If you make backwards incompatible changes to the recipe format:

  • Update ESMValTool and link the pull request(s) in the description

To help with the number pull requests:

@valeriupredoi
Copy link
Contributor

nice one @bvreede - but the important question is if an actual task (not a mock task) runs on OSX without setting the multiproc method at the start of the script? Since that's what was getting raised by the failing test 👍

@bvreede
Copy link
Contributor Author

bvreede commented Feb 12, 2021

Thanks @valeriupredoi! As far as I understand, the task itself runs with either spawn or fork; the issue we zeroed in on was with the test. Fwiw running recipes on mac osx with python >3.8 works well as far as I've seen — have yet to encounter an error. Are there any issues outside of this failing test that we know of, that were fixed by setting multiprocessing to fork?

The method that was used in this test is a monkeypatched _run method that is still used, except now called in a different way; i.e. MockBaseTask._run.

@valeriupredoi
Copy link
Contributor

great! if you confirm that you are able to run a few example recipes on OSX with Python>=3.8 and max_parallel_tasks: set to 2 or more in the config-user then it means we good to go and in business 👍 🍺

@bvreede
Copy link
Contributor Author

bvreede commented Feb 12, 2021

I can confirm this!

@bvreede
Copy link
Contributor Author

bvreede commented Feb 12, 2021

Is that enough? :)

Copy link
Contributor

@valeriupredoi valeriupredoi left a comment

Choose a reason for hiding this comment

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

excellent work 🥳

@valeriupredoi
Copy link
Contributor

valeriupredoi commented Feb 12, 2021

Is that enough? :)

absolutely! I feel like a blind man trying to figure all this stuff only relying on the remote GA machine. Good stuff! If I am not too much of a nuisance, would you be able to have a look at the GA tests next, include OSX fully - for tests and builds etc 🍺

@bvreede
Copy link
Contributor Author

bvreede commented Feb 12, 2021

If you can explain to me what the GA tests are 😅 absolutely.
[Apologies; new to this!]

@valeriupredoi
Copy link
Contributor

sorry - Github Actions, you can find them in .github/workflows and let me know if you have questions about them, I'd be very happy to assist!

Copy link
Contributor

@stefsmeets stefsmeets left a comment

Choose a reason for hiding this comment

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

To ensure that this is working with spawn, can you add a test with a context manager:
i.e. something like this:

with multiprocessing.get_context('spawn').Pool() as pool:
    pool.map(function, args)

@bvreede
Copy link
Contributor Author

bvreede commented Feb 12, 2021

@valeriupredoi

The failing test in GA is the same as the one that's failing on my machine. The latest run on master shows the following failure summary:

FAILED tests/integration/test_task.py::test_run_tasks[2] - TypeError: 'NoneTy...
FAILED tests/integration/test_task.py::test_run_tasks[3] - TypeError: 'NoneTy...
FAILED tests/integration/test_task.py::test_run_tasks[4] - TypeError: 'NoneTy...
FAILED tests/integration/test_task.py::test_run_tasks[None] - TypeError: 'Non...
FAILED tests/integration/test_task.py::test_run_tasks[16] - TypeError: 'NoneT...
FAILED tests/integration/cmor/_fixes/cmip6/test_cesm2.py::test_cl_fix_file

The last one is new to me, however; and it does not fail locally with python 3.8 and 3.9.
Can we add 3.9 to GA tests for OSX? There's a comment that ESMValTool does not work well for 3.9, but it's not clear to me why. It would be informative to see whether this test also fails for 3.9, for one.

@valeriupredoi
Copy link
Contributor

sure - go for it! That's my old comment before we've done all the good stuff with Python 3.9. Pls reinstate all the tests I commented out and add whatever you think it's needed so we start understanding what's going on in OSX land (well, more like you start understanding coz I am OSX-less 😁 ). But let's first merge this and continue work in a new PR, I reckon

@bvreede
Copy link
Contributor Author

bvreede commented Feb 13, 2021

Thanks for the review @stefsmeets! I agree it's a good idea to make sure that the tests (and the software) work with both multiprocessing methods — but given that we have now explicitly removed the dependency on spawn/fork from this test, it doesn't make sense to me to add this condition. Or am I missing something?
It does make sense to test the task function itself under both methods — would this do that?
Appreciate your clarification, I'm learning tons!

@stefsmeets
Copy link
Contributor

Thanks for the review @stefsmeets! I agree it's a good idea to make sure that the tests (and the software) work with both multiprocessing methods — but given that we have now explicitly removed the dependency on spawn/fork from this test, it doesn't make sense to me to add this condition. Or am I missing something?
It does make sense to test the task function itself under both methods — would this do that?
Appreciate your clarification, I'm learning tons!

Hi @bvreede , good question! This is to make sure that we do not silently introduce a bug that affects the multiprocessing behaviour. i.e. if we want to transition to using 'spawn' eventually / support osx, we might as well add a test right now to ensure any change in behaviour of esmvalcore will cause the test to fail for both methods.

@bouweandela
Copy link
Member

@bvreede Could you please merge the master branch into this pull request, to see if all tests now pass?

bvreede and others added 2 commits February 16, 2021 13:19
Co-authored-by: bouweandela <b.andela@esciencecenter.nl>
@bvreede
Copy link
Contributor Author

bvreede commented Feb 16, 2021

Not sure if I did that in the most elegant way, but all tests pass now! Merci bien.

Copy link
Contributor

@stefsmeets stefsmeets left a comment

Choose a reason for hiding this comment

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

Hi @bvreede , nice work! Looks fine to me. I'm just wondering why this works, because it seems like it is almost the same as before. I'm not entirely happy how the second test (test_runner_uses_priority) now monkeypatches MockBaseTask, but I guess it is the way it is for now. I hope it won't cause issues for the next person debugging this in the future.

Just a small comment on the code and then it is good to go. 🚀

@stefsmeets stefsmeets self-requested a review February 18, 2021 13:07
@stefsmeets stefsmeets changed the title Fix unittests for macOSX with Python >3.8 Fix tests for multi-processing with spawn method (i.e. macOSX with Python>3.8) Feb 18, 2021
@stefsmeets
Copy link
Contributor

All good, I have not strong enough opinions whether this should be mp or multiprocessing, so this can be merged @valeriupredoi 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error message for 'spawn' multiprocessing method
4 participants