Multithreading apply_macros#225
Open
James Bruten (james-bruten-mo) wants to merge 2 commits intoMetOffice:mainfrom
Open
Multithreading apply_macros#225James Bruten (james-bruten-mo) wants to merge 2 commits intoMetOffice:mainfrom
James Bruten (james-bruten-mo) wants to merge 2 commits intoMetOffice:mainfrom
Conversation
Erica Neininger (ericaneininger)
approved these changes
Apr 27, 2026
Contributor
Erica Neininger (ericaneininger)
left a comment
There was a problem hiding this comment.
I'm happy with this
Contributor
R Sharp (r-sharp)
left a comment
There was a problem hiding this comment.
One wee Q for the author...
| "[PASS] Upgraded rose-stem app " | ||
| f"{upgradeable_apps[upgrade_tasks.index(task)].name} successfully" | ||
| ) | ||
|
|
Contributor
There was a problem hiding this comment.
Rather than running executor.shutdown on line 1180, might it be better to allow all the tasks to be attempted and then list the macros that didn't upgrade and stop ?
Where there's one fail, there might be others.
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.
PR Summary
Sci/Tech Reviewer: Erica Neininger (@ericaneininger)
Code Reviewer: R Sharp (@r-sharp)
This attempts to introduce some parallelism to apply_macros. Given most of the script involves writing out macros and upgrading apps, all of which are fully independent, adding parallelism is trivial. The only part of the script which can't be easily parallelised is the initial processing of the macros - this part is very fast anyway.
This uses
concurrent.futures.ThreadPoolExecutorto implement multi-threading. I've also tested with multi-processing, but this was slightly slower overall. Running with 4 threads for a macro added togunghohas a runtime of 99s, vs 190s with 1 thread.Handling of errors withing threaded regions has also been checked and this works as expected.
Code Quality Checklist
Testing
Script run for a test macro with correct output produced and errors raised when appropriate.
Security Considerations
AI Assistance and Attribution
Sci/Tech Review
(Please alert the code reviewer via a tag when you have approved the SR)
Code Review