mirror of
https://github.com/modelscope/modelscope.git
synced 2026-07-09 20:09:17 +02:00
fix: patch_context() use try/finally to ensure unpatch on exception (#1743)
- Wrapped yield in try/finally block so unpatch_hub() executes even when the with-body raises an exception, preventing patch state leakage
This commit is contained in:
@@ -1014,5 +1014,7 @@ def unpatch_hub():
|
||||
@contextlib.contextmanager
|
||||
def patch_context():
|
||||
patch_hub()
|
||||
yield
|
||||
unpatch_hub()
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
unpatch_hub()
|
||||
|
||||
Reference in New Issue
Block a user