You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
restore_original_limits() restores all libraries, not just those that were set #308
Splitting off from discussion in #300, though it might end up getting fixed there. Original report from @cakedev0, lightly edited:
Claude had this finding:
The second one is similar to the bug of #299 in a sibling code path: restore_original_limits also restores the libraries that this limiter never set. A thread that only limits OpenMP (or passes limits=None) still holds an OpenBLAS snapshot, and on exit it takes control to restore it:
Keeping in _original_info only the libraries that _set_threadpool_limits did set (dropping the entry on the continue path and when num_threads is None) should cover it. WDYT?
My second thought is that the current status quo is somewhat ambiguous. restore_original_limits() could mean one of two things:
Restore to the status quo upon the creation of the object, the current code.
Or, restore those limits that were explicitly set when the object was created, the proposed change.
Consider for example the case where one does threadpool_limit(limits=None). This doesn't set/limit anything, yet clearly the expectation (and how it's used) is that restore_original_limits() will restore everything. So even if we go with option 2 above, limits=None needs to be a special case.
After some more thought I think the original bug report is reasonable, and the limits=None can be explained not so much as a special case but as "you're setting everything to the current value", so restoring everything makes sense. I'll do this in its own PR I think.
Activity
itamarst commentedon Nov 17, 2026
So my first thought was that this is a real bug.
My second thought is that the current status quo is somewhat ambiguous.
restore_original_limits()could mean one of two things:Consider for example the case where one does
threadpool_limit(limits=None). This doesn't set/limit anything, yet clearly the expectation (and how it's used) is thatrestore_original_limits()will restore everything. So even if we go with option 2 above,limits=Noneneeds to be a special case.itamarst commentedon Nov 18, 2026
After some more thought I think the original bug report is reasonable, and the
limits=Nonecan be explained not so much as a special case but as "you're setting everything to the current value", so restoring everything makes sense. I'll do this in its own PR I think.itamarst commentedon Nov 18, 2026
I guess that does raise the question of what
get_original_num_threads()should do—should it return all limits, or just the ones that were modified?itamarst commentedon Nov 18, 2026
I went with
get_original_num_threads()should only return results for APIs that were modified.