Can I safely do inference from another thread when using tf.train.Optimizer(use_locking=True)?
<p>I have several threads that run operation on the same TensorFlow graph. The operations are either inference or optimization of a neural network. I can use the <code>use_locking</code> parameter for the optimizer to prevent concurrent updates of the variables.</p>

<p>However, does this safe me from reading partially updated versions of the weights when doing inference at the same time? If not, how can I ensure this and is a Python lock around all <code>sess.run()</code> a good alternative?</p>

<p>Do your inference calls need to be on an up-to-date version of the graph? If you don't mind some delay, you could make a copy of the graph by calling sess.graph.as_graph_def on the training thread, and then create a new session on the inference thread using that graph_def periodically.</p>

python multithreading thread-safety locking tensorflow