units
units copied to clipboard
EOFError with pytest-xdist
See hgrecco/flexcache#6. This occurs after the cache_folder argument here was added in #48: https://github.com/IAMconsortium/units/blob/d4f0ffd973bfc99891a33238a3b6f6add688c6f8/iam_units/init.py#L20-L21
Code that uses iam-units and pytest-xdist together is affected. The error occurs sporadically/non-deterministically, depending on which xdist worker(s) are trying to write/read the cache file.
One way to resolve would be:
- Use an optional environment variable for the cache_folder, e.g.:
registry = pint.UnitRegistry(cache_folder=os.environ.get("IAM_UNITS_CACHE", ":auto:")) - In multiprocessing situations (such as with
pytest-xdist), set a distinct value for this environment variable in each process.
#55 added the proposed resolution, but I'll leave this issue open until we learn whether the upstream one is "won't fix" or will be resolved. In the latter case, then use of the environment variable may become redundant.