Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Tensorflow session.run()释放GIL_Python_Multithreading_Tensorflow - Fatal编程技术网

Python Tensorflow session.run()释放GIL

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):

据我所知(基于在线阅读),Tensorflow中的session.run()释放了Python GIL(全局解释器锁),这通常会阻止多线程在Python中以最佳方式工作。如果这是真的,那么如果我并行运行多个会话,多线程应该会提供显著的性能优势,对吗

我实现了下面的代码,但它仍然以相同的速度运行,就像按顺序运行一样。我是否在某个地方错误地实现了它?还是我的理解不正确

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