Skip to content

Commit 0aa9632

Browse files
Fix bare except in Stream_accept that swallows all exceptions (#1631) (#1632)
Narrow the catch from bare `except: pass` to `except TypeError` with a string check, so that only missing `__cuda_stream__` is silently handled. Buggy protocol implementations and other exceptions now propagate correctly. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 7832aaf commit 0aa9632

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

cuda_core/cuda/core/_stream.pyx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -470,18 +470,14 @@ cdef Stream Stream_accept(arg, bint allow_stream_protocol=False):
470470
return <Stream>(arg)
471471
elif isinstance(arg, GraphBuilder):
472472
return <Stream>(arg.stream)
473-
elif allow_stream_protocol:
474-
try:
475-
stream = Stream._init(arg)
476-
except:
477-
pass
478-
else:
479-
warnings.warn(
480-
"Passing foreign stream objects to this function via the "
481-
"stream protocol is deprecated. Convert the object explicitly "
482-
"using Stream(obj) instead.",
483-
stacklevel=2,
484-
category=DeprecationWarning,
485-
)
486-
return <Stream>(stream)
473+
elif allow_stream_protocol and hasattr(arg, "__cuda_stream__"):
474+
stream = Stream._init(arg)
475+
warnings.warn(
476+
"Passing foreign stream objects to this function via the "
477+
"stream protocol is deprecated. Convert the object explicitly "
478+
"using Stream(obj) instead.",
479+
stacklevel=2,
480+
category=DeprecationWarning,
481+
)
482+
return <Stream>(stream)
487483
raise TypeError(f"Stream or GraphBuilder expected, got {type(arg).__name__}")

0 commit comments

Comments
 (0)