title: Reusing Tensorflow session in multiple threads causes crash
body: <p><strong>Background:</strong> </p>
  
  <p>I have some complex reinforcement learning algorithm that I want to run in multiple threads. </p>
  
  <p><strong>Problem</strong></p>
  
  <p>When trying to call <code>sess.run</code> in a thread I get the following error message:</p>
  
  <p><code>RuntimeError: The Session graph is empty.  Add operations to the graph before calling run().</code></p>
  
  <p><strong>Code reproducing the error:</strong></p>
  
  <pre><code>import tensorflow as tf
  
  import threading
  
  def thread_function(sess, i):
      inn = [1.3, 4.5]
      A = tf.placeholder(dtype=float, shape=(None), name="input")
      P = tf.Print(A, [A])
      Q = tf.add(A, P)
      sess.run(Q, feed_dict={A: inn})
  
  def main(sess):
  
      thread_list = []
      for i in range(0, 4):
          t = threading.Thread(target=thread_function, args=(sess, i))
          thread_list.append(t)
          t.start()
  
      for t in thread_list:
          t.join()
  
  if __name__ == '__main__':
  
      sess = tf.Session()
      main(sess)
  </code></pre>
  
  <p>If I run the same code outside a thread it works properly.</p>
  
  <p>Can someone give some insight on how to use Tensorflow sessions properly with python threads?</p>