Skip to content

Commit

Permalink
Merge pull request #3026 from jsiirola/fix-gurobi-pint-dask-interaction
Browse files Browse the repository at this point in the history
Fix exception due to interaction among Gurobi, Pint, Dask, and Threading
  • Loading branch information
blnicho authored Oct 31, 2023
2 parents 96c4c0b + 43043e0 commit 2458a8f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pyomo/core/base/units_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,19 @@ def __getattribute__(self, attr):
# present, at which point this instance __class__ will fall back
# to PyomoUnitsContainer (where this method is not declared, OR
# pint is not available and an ImportError will be raised.
#
# We need special case handling for __class__: gurobipy
# interrogates things by looking at their __class__ during
# python shutdown. Unfortunately, interrogating this
# singleton's __class__ evaluates `pint_available`, which - if
# DASK is installed - imports dask. Importing dask creates
# threading objects. Unfortunately, creating threading objects
# during interpreter shutdown generates a RuntimeError. So, our
# solution is to special-case the resolution of __class__ here
# to avoid accidentally triggering the imports.
if attr == "__class__":
return _DeferredUnitsSingleton
#
if pint_available:
# If the first thing that is being called is
# "units.set_pint_registry(...)", then we will call __init__
Expand Down

0 comments on commit 2458a8f

Please sign in to comment.