title: 'NoneType' object has no attribute 'raise_exception_on_not_ok_status'
body: <p>When I define a function to perform neural network training, I get an error. But, when I do that without making it function, there is no error. Why?</p>
  
  <pre><code>def myneural():
  
      import numpy as np
      import keras
      from keras import backend as K
      from keras.layers import Input, Dense, Activation
      from keras.models import Model, Sequential
  
  
      x_train_s = np.random.randint(5, size=(20, 2))
      x_test_s = x_train_s
  
      model = Sequential([
          Dense(10, input_shape=(2,)),
          Activation('linear'),
          Dense(2),
          Activation('linear')
      ])
  
  
      model.compile(optimizer='adam', loss='mean_squared_error')
  
      fittingadam = model.fit(x_train_s, x_train_s, epochs=2,
                              validation_data=(x_test_s, x_test_s),
                              shuffle=True, verbose=1, batch_size=None)
  
  
      encoder = K.function([model.layers[0].input],
                           [model.layers[1].output])
  
      code = encoder([x_test_s])[0]
  
  
  
  myneural()
  </code></pre>
  
  <p>The error I get is:</p>
  
  <pre><code>Using TensorFlow backend.
  WARNING:tensorflow:From C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
  Instructions for updating:
  Colocations handled automatically by placer.
  WARNING:tensorflow:From C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\ops\math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
  Instructions for updating:
  Use tf.cast instead.
  Train on 20 samples, validate on 20 samples
  Epoch 1/2
  2019-10-03 14:34:50.275279: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
  
  20/20 [==============================] - 0s 7ms/step - loss: 4.0432 - val_loss: 3.9670
  Epoch 2/2
  
  20/20 [==============================] - 0s 53us/step - loss: 3.9670 - val_loss: 3.8917
  Exception ignored in: &lt;function BaseSession._Callable.__del__ at 0x0000021A829C1378&gt;
  Traceback (most recent call last):
    File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1453, in __del__
  AttributeError: 'NoneType' object has no attribute 'raise_exception_on_not_ok_status'
  
  Process finished with exit code 0
  </code></pre>
  
  <p>But, when I delete the first line and last line and remove indents from other lines, there will be no error.</p>
  
  <p><strong>First question:</strong> Why is that? How can I resolve it to run it without any problems as a function?</p>
  
  <p><strong>Second question:</strong> What about the warnings? Are they important? How can I get rid of them?</p>