xonsh / lazyasd

Lazy & self-destructive tools for speeding up module imports
http://xon.sh
BSD 3-Clause "New" or "Revised" License
52 stars 8 forks source link

Implement fine-grained control of bg module load delay #8

Open paulie-g opened 5 years ago

paulie-g commented 5 years ago

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:

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.

scopatz commented 5 years ago

Thanks so much for putting this in @paulie-g!

scopatz commented 5 years ago

And sorry for taking so long to review this

scopatz commented 5 years ago

This looks great! Could you please add a news entry, as per https://regro.github.io/rever-docs/news.html

Happy to merge this and then do a release!

paulie-g commented 5 years ago

I'm happy to do that if you like, although I would've thought this would be done by the person doing the release. How would you like to label and formulate the change? Presumably there's a standard for enhancements, 'Added'? How much detail is usually in the news entries?

scopatz commented 5 years ago

I'm happy to do that if you like, although I would've thought this would be done by the person doing the release.

Yeah, we democratize the release process so that it is part of the PR. As you can see in https://regro.github.io/rever-docs/news.html all you need to do to get started is go into the news/ dir and copy the TEMPLATE file over to a new file (usually named after the branch) and then fill in that new file.