吴裕雄 python 神经网络——TensorFlow 队列操作

import tensorflow as tf

q = tf.FIFOQueue(2, "int32")
init = q.enqueue_many(([0, 10],))
x = q.dequeue()
y = x + 1
q_inc = q.enqueue([y])
with tf.Session() as sess:
    init.run()
    for _ in range(5):
        v, _ = sess.run([x, q_inc])
        print(v)

吴裕雄 python 神经网络——TensorFlow 队列操作

import time
import threading
import numpy as np

def MyLoop(coord, worker_id):
    while not coord.should_stop():
        if np.random.rand()<0.1:
            print("Stoping from id: %d\n" % worker_id,coord.request_stop())
        else:
            print("Working on id: %d\n" % worker_id, time.sleep(1))
coord = tf.train.Coordinator()
threads = [threading.Thread(target=MyLoop, args=(coord, i, )) for i in xrange(5)]
for t in threads:
    t.start()
coord.join(threads)

吴裕雄 python 神经网络——TensorFlow 队列操作

 

上一篇:两个场景下Mysqldump数据库备份恢复


下一篇:[Java多线程](八)生产消费者问题