Merge lp:~gz/bzr/lazy_import_threadsafe_396819 into lp:bzr
Status: | Merged |
---|---|
Approved by: | Vincent Ladeuil |
Approved revision: | no longer in the source branch. |
Merged at revision: | 6426 |
Proposed branch: | lp:~gz/bzr/lazy_import_threadsafe_396819 |
Merge into: | lp:bzr |
Diff against target: |
433 lines (+85/-114) 4 files modified
bzrlib/builtins.py (+11/-2) bzrlib/lazy_import.py (+45/-58) bzrlib/tests/test_lazy_import.py (+24/-54) doc/en/release-notes/bzr-2.5.txt (+5/-0) |
To merge this branch: | bzr merge lp:~gz/bzr/lazy_import_threadsafe_396819 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Vincent Ladeuil | Approve | ||
Martin von Gagern (community) | Approve | ||
Review via email: mp+87525@code.launchpad.net |
Commit message
Make lazy imports proxy by default so that concurrent resolution is robust
Description of the change
Switch the default behaviour of lazy imports to do object proxying rather than raise an exception, which is the simplest and safest way of ensuring concurrent usage doesn't break. What this loses us is some detection of badly written code where a proxied object is aliased in more than one location, so copies persist even after the original is replaced by the resolved object.
This is a version of Martin von Gagern's branch, with some minor cleanups, and the complication of tracking the last replacement removed. This loses part of the compensation for changing the error detection, which was to flip proxying back to disallowed for selftest. Now imports that happen before that point will not be flagged. This is a minor additional loss, as selftest is already very limited in how it can track lazy imports, given it will only do one path and running other commands may take another, with different import order and behaviours.
The proposal doesn't mark without prerequisite set as the diff against trunk is quite different, but the changes against MvG's branch are also of interest:
<https:/
There's a lot of prior discussion, but the short version is that without locks (which we don't want, and are dangerous when combined with python imports), the only way to support concurrent resolution of lazy objects is to accept that sometimes the factory will be called more than once, and not to treat that as an error. Detecting coding mistakes has to be left to other mechanisms than always raising an exception when a lazy object is used multiple times.
Had a look at the individual changesets; they all look good to me.
Why ScopeReplacer. _should_ proxy instead of object. __getattribute_ _(self, '_should_proxy')? The latter would allow overriding, although we don't need it yet. Performance shouldn't be an issue here, as this will be called rarely. Is it for the sake of readability?
Diff below shows merge problems, so you should probably pull from trunk and merge manually.
I'm setting review to Approve in LP, although I'm no core dev. Hope you won't consider this presumptuous of me.