Skip to content

Commit 54fa129

Browse files
committed
Use warning when calling restore more than patch in a thread
1 parent f048c07 commit 54fa129

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

mkl_random/_patch_numpy.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
"""Define functions for patching NumPy with MKL-based NumPy interface."""
2727

28+
import warnings
2829
from contextlib import ContextDecorator
2930
from threading import Lock, local
3031

@@ -85,11 +86,12 @@ def do_restore(self, verbose=False):
8586
with self._lock:
8687
local_count = getattr(self._tls, "local_count", 0)
8788
if local_count <= 0:
88-
if verbose:
89-
print(
90-
"Warning: restore_numpy_random called more times than "
91-
"patch_numpy_random in this thread."
92-
)
89+
warnings.warn(
90+
"restore_numpy_random called more times than "
91+
"patch_numpy_random in this thread.",
92+
RuntimeWarning,
93+
stacklevel=2,
94+
)
9395
return
9496
self._tls.local_count -= 1
9597
self._patch_count -= 1

0 commit comments

Comments
 (0)