Implement fine-grained control of bg module load delay #8
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.
The background module loader delays before importing the given module. Currently, it does this in one particular way - check len(sys.modules) and proceed only when it stops growing. The parameters it uses to do so are hardcoded.
I have implemented parametrization for this functionality. Caller can now pass in an object with a wait() interface. The existing method is still the default complete with its previously hardcoded parameters, although they can now be changed at call-time. Additional delay implementations have been added:
I've added the comments and unit tests for all of them.
My particular use case involves needing to avoid time.sleep() there (the Noop case), because it triggers a deadlock when running tests under nose. However, I think the others might be useful to others.
To be clear: the default path has not functionally changed and all unit tests pass.