Version Checks (indicate both or one)
Issue Description
Hi,
Mosek licenses are bound to the environment and within several Tasks can be created. solver.py calls mosek.Task() without explicit environment and that creates a "private linopy" env. Even if you're not aiming to run a mosek solve you're blocking a license it seems.
Full disclosure: Claude found this, I can't really vogue for this. It seems to be sure though, but they always are. But it seems to fix the leak.
_PATCH_FROM = (
" with contextlib.suppress(mosek.Error):\n"
" t = mosek.Task()\n"
" t.optimize()\n"
"\n"
" available_solvers.append("mosek")"
)
_PATCH_TO = (
" # PATCHED by linopy_mosek_probe_fix: use a context-managed Env+Task\n"
" # so the probe does not leak a PTS license token forever.\n"
" with contextlib.suppress(mosek.Error):\n"
" with mosek.Env() as _probe_env, _probe_env.Task(0, 0) as _probe_task:\n"
" _probe_task.optimize()\n"
" available_solvers.append("mosek")"
)
Cheers,
Andreas
Reproducible Example
Expected Behavior
see above
Installed Versions
Details
Replace this line.
Version Checks (indicate both or one)
I have confirmed this bug exists on the lastest release of Linopy.
I have confirmed this bug exists on the current
masterbranch of Linopy.Issue Description
Hi,
Mosek licenses are bound to the environment and within several Tasks can be created. solver.py calls mosek.Task() without explicit environment and that creates a "private linopy" env. Even if you're not aiming to run a mosek solve you're blocking a license it seems.
Full disclosure: Claude found this, I can't really vogue for this. It seems to be sure though, but they always are. But it seems to fix the leak.
_PATCH_FROM = (
" with contextlib.suppress(mosek.Error):\n"
" t = mosek.Task()\n"
" t.optimize()\n"
"\n"
" available_solvers.append("mosek")"
)
_PATCH_TO = (
" # PATCHED by linopy_mosek_probe_fix: use a context-managed Env+Task\n"
" # so the probe does not leak a PTS license token forever.\n"
" with contextlib.suppress(mosek.Error):\n"
" with mosek.Env() as _probe_env, _probe_env.Task(0, 0) as _probe_task:\n"
" _probe_task.optimize()\n"
" available_solvers.append("mosek")"
)
Cheers,
Andreas
Reproducible Example
Expected Behavior
see above
Installed Versions
Details
Replace this line.