units icon indicating copy to clipboard operation
units copied to clipboard

EOFError with pytest-xdist

Open khaeru opened this issue 4 months ago • 1 comments

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:

  1. Use an optional environment variable for the cache_folder, e.g.:
    registry = pint.UnitRegistry(cache_folder=os.environ.get("IAM_UNITS_CACHE", ":auto:"))
    
  2. In multiprocessing situations (such as with pytest-xdist), set a distinct value for this environment variable in each process.

khaeru avatar Sep 24 '25 08:09 khaeru

#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.

khaeru avatar Oct 20 '25 09:10 khaeru