In tensorflow, what should we do if we want run something before fetching data (such as, using queue in tensorflow)? Here is an example tested by myself:

import tensorflow as tf
from tensorflow.python.framework import ops
def my_func(x):
    return x
queue = tf.FIFOQueue(10, "float32")
init  = queue.enqueue_many(([1, 2, 3],))
my_op = tf.py_func(my_func, [1.0], tf.float32)
with ops.control_dependencies([my_op]):
    inc = queue.enqueue([1],)
with tf.Session() as sess:
    print("Before Enqueue")
    print("After Enqueue")

It will print

Before Enqueue
After Enqueue

Successfully, we add an operation before enqueue a item into queue.