Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect interpreter shutdown for proper __del__ behavior #2809

Merged
merged 1 commit into from
Dec 13, 2019

Conversation

emcastillo
Copy link
Member

@emcastillo emcastillo commented Dec 13, 2019

Closes #2806, #2658, and #2777

In some python interpreters (mostly installed with pyenv)
The following one-liner causes an exception in object destruction during interpreter shutdown.
python -c 'import cupy; stream = cupy.cuda.Stream()'

When finishing program execution, python does not guarantee the order in which objects are destroyed.

Calls inside a del method calling other objects or modules are not guaranteed to be correctly executed as those objects can be already deleted.

PEP442 should address this, but we have seen this problem persists.

This solution is obtained from Numba/llvmlite code.

@emcastillo emcastillo force-pushed the fix_shutdown branch 2 times, most recently from 298195a to 77a558e Compare December 13, 2019 08:21
@niboshi
Copy link
Member

niboshi commented Dec 13, 2019

A nitpick but how about this way?

if is_shutting_down():
    return

No extra indentation needed, not complicating conditions, and you can write the same way for any clean up code.

cupy/random/generator.py Outdated Show resolved Hide resolved
@emcastillo
Copy link
Member Author

Thanks for comments.

@niboshi
Copy link
Member

niboshi commented Dec 13, 2019

LGTM
Jenkins, test this please

@pfn-ci-bot
Copy link
Collaborator

Successfully created a job for commit 3ef0d3b:

@chainer-ci
Copy link
Member

Jenkins CI test (for commit 3ef0d3b, target branch master) succeeded!

@niboshi niboshi self-assigned this Dec 13, 2019
@niboshi niboshi added cat:bug Bugs to-be-backported Pull-requests to be backported to stable branch labels Dec 13, 2019
@niboshi niboshi added this to the v8.0.0a1 milestone Dec 13, 2019
@niboshi niboshi merged commit f121d14 into cupy:master Dec 13, 2019
niboshi added a commit to niboshi/cupy that referenced this pull request Dec 13, 2019
Detect interpreter shutdown for proper `__del__` behavior
niboshi added a commit to niboshi/cupy that referenced this pull request Dec 13, 2019
Detect interpreter shutdown for proper `__del__` behavior
@emcastillo emcastillo deleted the fix_shutdown branch December 15, 2019 02:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cat:bug Bugs to-be-backported Pull-requests to be backported to stable branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

__del__ behavior on interpreter shutdown
5 participants