tensorflow: Bug: Exception ignored in BaseSession.__del__
Hello Everyone,
The following code produces an error in TensorFlow:
import tensorflow as tf
a = tf.constant(123)
b = tf.constant(456)
c = a * b
session = tf.Session()
# A slightly different error is produced if this is removed.
session.run(tf.initialize_all_variables())
result = session.run(c)
print(result)
session.close() # The error is produced regardless of this.
#quit() # This produces the error.
import sys
sys.exit() # This also produces the error.
This is the contents of sandbox3.py which I run in PyCharm.
The output is:
/home/magnus/anaconda3/envs/tensorflow/bin/python /home/magnus/development/TensorFlow-Tutorials/sandbox3.py
56088
Exception ignored in: <bound method BaseSession.__del__ of <tensorflow.python.client.session.Session object at 0x7fb4ecd301d0>>
Traceback (most recent call last):
File "/home/magnus/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 171, in __del__
File "/home/magnus/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 167, in close
AttributeError: 'NoneType' object has no attribute 'raise_exception_on_not_ok_status'
Process finished with exit code 0
I’m using the following versions:
- TensorFlow 0.9.0 CPU installed from binary.
- Python 3.5.1
- Anaconda 2.5.0
- PyCharm 5.0.4
- Linux Mint 17.3
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 7
- Comments: 44 (5 by maintainers)
Links to this issue
Commits related to this issue
- Apply fix for https://github.com/tensorflow/tensorflow/issues/3388 — committed to mationai/keras by mationai 7 years ago
- Avoid raising an exception when we fail to delete a session on shutdown. Fixes #3388. Change: 150265211 — committed to jhseu/tensorflow by mrry 7 years ago
- ・ラベルを指定して学習する機能を削除 ・DBから処理対象の画像を取得し、学習モデルの分析結果をDBへ返す(update)機能を実装。 ・hashの処理時間をprintする ・tensorflow処理後にエラーが発生する不具合を修正。 参考サイト: https://github.com/tensorflow/tensorflow/issues/3388 — committed to t-analyzers/tweet-analyzer by furuhito0519 7 years ago
- added session closure at the end of the code to address https://github.com/tensorflow/tensorflow/issues/3388 — committed to pantelis/CarND-Behavioral-Cloning-P3 by pantelis 7 years ago
- Ubuntu keras fix: see https://github.com/tensorflow/tensorflow/issues/3388 — committed to boing102/CI-Project by deleted user 7 years ago
- Update Keras Example for (Parikh et al, 2016) implementation (#2803) * bug fixes in keras example * created contributor agreement * baseline for Parikh model * initial version of parikh 201... — committed to explosion/spaCy by free-variation 6 years ago
- 💫 Port master changes over to develop (#2979) * Create aryaprabhudesai.md (#2681) * Update _install.jade (#2688) Typo fix: "models" -> "model" * Add FAC to spacy.explain (resolves #2706) ... — committed to explosion/spaCy by ines 6 years ago
@ksrinivs64 try to delete session from keras backend:
Same bug with me, anyway, it didn’t happen every time, just occasionally.
it induced by different gc sequence, if python collect session first , the program will exit successfully, if python collect swig memory(tf_session) first, the program exit with failure.
you can force python to del session by:
del sessionor if you are using keras, you cant get the session instance, you can run folloing code at end of your code:
import gc; gc.collect()So can someone tell me what the final fix is? python 3.5, keras with tf backend. same problem.
Unfortunately, after b21c69a fix, this exception will come up oftenly (not every time.):
and sometimes:
Hello everyone,
Same issue still happening to me occasionally even though I cleared the TF session with
K.clear_session()as @hosford42 suggested after the code was done. @Nimi42 also suggested that in #8652. I also tried clearing the session before each forward pass to no avail.Adding
import tensorflow as tfbefore importing Keras like @Ares513 suggested in #8652 didn’t work either.I’m making inferences on multiple images, which are kicked off from separate bash scripts that are executing sequentially so I’m wondering if clearing the session would actually help since every forward pass of my net is invoked from a different process.
I’m using python 3.4, keras 2.1.6, and tensorflow 1.8.0 (no GPU support).
This is the error:
Exception ignored in: <bound method Session.__del__ of <tensorflow.python.client.session.Session object at 0x7f037640b198>> Traceback (most recent call last): File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/client/session.py", line 707, in __del__ TypeError: 'NoneType' object is not callableDon’t know if it may be related but this is also a warning I get each time I run my inference script:
/usr/lib/python3.4/importlib/_bootstrap.py:321: FutureWarning: Conversion of the second argument of issubdtype fromfloattonp.floatingis deprecated. In future, it will be treated asnp.float64 == np.dtype(float).type. return f(*args, **kwds)#8652 is related and some also solved it by placing
K.clear_session()after all the code was done. Note that contrary to what the author of #8652 states this issue is not closed and @naatje80 mentions it’s a Keras issue but this is a related Keras issue that was closed stating it’s a TF issue. This issue is also related and was also closed stating it’s a tensorflow issue.This is a nagging issue which is very important for me to sort out due to an upcoming checkpoint for the xView dataset challenge (June 15). If anyone can shed some light on this I will greatly appreciate it.
Thanks in advance.
For those using tensorflow as keras backend, you may add the following function to your code. It is also useful in case you need to manage your memory.
Same issue happened occasionally.
Exception ignored in: <bound method BaseSession.del of <tensorflow.python.client.session.Session object at 0x7f88e5b52908>> Traceback (most recent call last): File “/home/wcai/tensorflow/lib/python3.5/site-packages/tensorflow/python/client/session.py”, line 701, in del TypeError: ‘NoneType’ object is not callable
Python 3.5.2 TensorFlow 1.3.0 GPU version installed by virtualenv Linux Mint 18 64-bit
Here’s code that reproduces the Keras problem for me from a recent build of my test system. Ubuntu 14.04, Python 3.4 (default OS version), TensorFlow 0.12.1, Keras 1.2.0. pima.csv is a copy of this file:
Update: Calling
backend.clear_session()instead ofgc.collect()does indeed seem to fix the problem. Yay for not relying on GC magic! But this still really ought to be fixed. 😃Another update: ITOT the
gc.collect()solution I attempted in my straight-up TensorFlow test ended up not working reliably either. So, I went from doing this:To doing this:
It’s a nondeterminstic error, so we’ll see if that takes.
Another: TF1.0.0, Win10
Exception ignored in: <bound method BaseSession.del of <tensorflow.python.client.session.Session object at 0x000001D3B79EF358>> Traceback (most recent call last): File “lib\tensorflow_gpu\tensorflow\python\client\session.py”, line 582, in del UnboundLocalError: local variable ‘status’ referenced before assignment
@liusida Hi I have commented out
tryandfinallyblock of code:Hope it wouldn’t have drastic impact down the road.