question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`__del__` behavior on interpreter shutdown

See original GitHub issue

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.

https://github.com/cupy/cupy/blob/master/cupy/cuda/stream.pyx#L185 It is known to fail because runtime module is already unloaded when __del__ is called.

https://docs.python.org/3/reference/datamodel.html#object.__del__

This can affect behavior on RAII pattern.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
emcastillocommented, Dec 13, 2019

Installed manually

Conda flags

-I$CONDA_PREFIX/include/python3.7m 
-I$CONDA_PREFIX/include/python3.7m  
-Wno-unused-result 
-Wsign-compare 
-march=nocona 
-mtune=haswell 
-ftree-vectorize 
-fPIC 
-fstack-protector-strong 
-fno-plt 
-O3 
-ffunction-sections 
-pipe  
-fdebug-prefix-map=/tmp/build/80754af9/python_1553721932202/work=/usr/local/src/conda/python-3.7.3 -fdebug-prefix-map=$CONDA_PREFIX=/usr/local/src/conda-prefix 
-fuse-linker-plugin 
-ffat-lto-objects 
-flto-partition=none 
-flto 
-DNDEBUG 
-fwrapv 
-O3 
-Wall

Pyenv python 3.7.3 flags (python3-config --cflags)

-I$HOME/.pyenv/versions/3.7.3/include/python3.7m 
-I$HOME/.pyenv/versions/3.7.3/include/python3.7m  
-Wno-unused-result 
-Wsign-compare 
-DNDEBUG 
-g 
-fwrapv 
-O3 
-Wall
1reaction
emcastillocommented, Dec 13, 2019

We just found that if we install python with pyenv, then it breaks just with python -c 'import cupy; stream = cupy.cuda.Stream()' Credit goes to @niboshi

Read more comments on GitHub >

github_iconTop Results From Across the Web

starting a thread in __del__ hangs at interpreter shutdown
It's due to creating the stdout/stderr worker threads from the __del__ finalizer while the interpreter is shutting down.
Read more >
[Python-Dev] Adding a scarier warning to object.__del__?
Hey everyone,. I just encountered yet another reason to beware of __del__: when it's called during interpreter shutdown, for reasons which are ...
Read more >
Where is Python's shutdown procedure setting module globals ...
CPython has a strange behaviour where it sets modules to None during shutdown. This screws up error logging during shutdown of some ...
Read more >
A Normal Accident In Python and mod_wsgi
During interpreter shutdown, None is somehow being called as a function. I'm no expert on Python's shutdown sequence, but I've never heard ...
Read more >
The 10 Most Common Mistakes That Python Developers Make
That way, when your program is finished executing (when exiting normally, that is), your registered handlers are kicked off before the interpreter is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found