Skip to content

Stream_accept uses bare except that swallows all exceptions #1631

Description

@Andy-Jost

Description

Stream_accept in _stream.pyx uses a bare except: pass when probing whether a foreign object supports the __cuda_stream__ protocol. This catches all exceptions, including KeyboardInterrupt, SystemExit, and RuntimeError from malformed protocol implementations.

Current behavior

try:
stream=Stream._init(arg)
except:
pass

Any exception raised during Stream._init is silently swallowed, including:

  • RuntimeError from a buggy __cuda_stream__ implementation (e.g., wrong return format)
  • TypeError from internal failures within __cuda_stream__()
  • KeyboardInterrupt, SystemExit

Expected behavior

Only the specific TypeError indicating the object lacks __cuda_stream__ should be caught. All other exceptions should propagate so that protocol implementation bugs are surfaced.

Proposed fix

Narrow the catch to except TypeError as e with a string check for "__cuda_stream__" in the message, which matches the specific TypeError raised by _handle_from_stream_protocol when the attribute is missing.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1Medium priority - Should dobugSomething isn't workingcuda.coreEverything related to the cuda.core module

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions