multi_thread.py 446 B

123456789101112131415161718
  1. import multiprocessing
  2. import tensorflow as tf
  3. def f(x):
  4. session = tf.Session()
  5. a = tf.Variable(x, name='a')
  6. b = tf.Variable(100, name='b')
  7. c = tf.multiply(a, b, name='c')
  8. session.run(tf.global_variables_initializer())
  9. out = session.run(c)
  10. print("OK: %s" % out)
  11. if __name__ == '__main__':
  12. multiprocessing.set_start_method('spawn') # Comment me out to hang
  13. f(0)
  14. multiprocessing.Pool().map(f, range(10))