Skip to content

[BUG]: Accessing Stream.handle in finalizer fails on module import #1748

@stiepan

Description

@stiepan

Is this a duplicate?

Type of Bug

Runtime Error

Component

cuda.core

Describe the bug

Starting with cuda.core 0.6, accessing Stream.handle when the Python is shutting down, fails with

ModuleNotFoundError: import of builtins halted; None in sys.modules

It used to work just fine before (0.5.1). Looks like as_py(..) is the culprit.

How to Reproduce

from cuda.core import Device

class MyClass:
    def __init__(self, stream):
        self.stream = stream

    def __del__(self):
        print("MyClass del", self.stream.handle)

dev = Device(0)
dev.set_current()
cp_stream = dev.create_stream()
my_stream = MyClass(cp_stream)

Expected behavior

Accessing the handle doesn't try to import modules and is safe to call from finalizers that may run on shutdown.

Operating System

No response

nvidia-smi output

No response

Metadata

Metadata

Assignees

Labels

P0High priority - Must do!bugSomething isn't workingcuda.coreEverything related to the cuda.core module

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions