Python Tensorflow session.run()释放GIL
据我所知(基于在线阅读),Tensorflow中的session.run()释放了Python GIL(全局解释器锁),这通常会阻止多线程在Python中以最佳方式工作。如果这是真的,那么如果我并行运行多个会话,多线程应该会提供显著的性能优势,对吗 我实现了下面的代码,但它仍然以相同的速度运行,就像按顺序运行一样。我是否在某个地方错误地实现了它?还是我的理解不正确Python Tensorflow session.run()释放GIL,python,multithreading,tensorflow,Python,Multithreading,Tensorflow,据我所知(基于在线阅读),Tensorflow中的session.run()释放了Python GIL(全局解释器锁),这通常会阻止多线程在Python中以最佳方式工作。如果这是真的,那么如果我并行运行多个会话,多线程应该会提供显著的性能优势,对吗 我实现了下面的代码,但它仍然以相同的速度运行,就像按顺序运行一样。我是否在某个地方错误地实现了它?还是我的理解不正确 def perform_inference_threaded_second(sess, input_list, output):
def perform_inference_threaded_second(sess, input_list, output):
output.append(np.asarray(sess.run(y_op, {x_inp: input_list})).astype(np.float32))
def perform_inference_threaded_parent_second(input_list):
inference_parent_start = time.perf_counter()
output = []
thread_list = []
for model_idx in range(len(model_names)):
sess = cr_sessions[model_idx]
with sess.as_default():
with curr_graph.as_default():
t = threading.Thread(target=perform_inference_threaded_second, args=(sess, input_list, output))
thread_list.append(t)
t.start() # start thread execution
for t in thread_list:
t.join() # block until the thread is finished
return output