The __eq__ method for instances of Unit (from a pint.UnitRegistry) compares the cached hash values for the two objects (source). Since Python 3.3, hash randomization has been enabled by default, meaning different Python interpreters will almost certainly produce different hashes for the same object. This includes Python interpreters created by multiprocessing with the spawn start method (default on Mac and Windows). Thus, when division is triggered from a subprocess and passed back to the main process, a simple == comparison of two Unit instances will result in False even when they are actually identical.
I don't love the idea of accessing private attributes to recalculate this hash as I've done in this PR. Suggestions are welcome!
By creating this pull request, I agree to the Contributor License
Agreement, which is available in CLA.md at the top level of this
repository.
The
__eq__
method for instances ofUnit
(from apint.UnitRegistry
) compares the cached hash values for the two objects (source). Since Python 3.3, hash randomization has been enabled by default, meaning different Python interpreters will almost certainly produce different hashes for the same object. This includes Python interpreters created bymultiprocessing
with thespawn
start method (default on Mac and Windows). Thus, when division is triggered from a subprocess and passed back to the main process, a simple==
comparison of twoUnit
instances will result inFalse
even when they are actually identical.I don't love the idea of accessing private attributes to recalculate this hash as I've done in this PR. Suggestions are welcome!
By creating this pull request, I agree to the Contributor License Agreement, which is available in
CLA.md
at the top level of this repository.