self._next_id_counter = 0 # GUARDED_BY(self._lock)
self._nodes_by_name = dict() # GUARDED_BY(self._lock)
self._version = 0 # GUARDED_BY(self._lock)
- # Current name stack: uniquified names
- self._name_stack = ""
# Maps a name used in the graph to the next id to use for that name.
self._names_in_use = {}
self._stack_state_is_thread_local = False
finally:
self._default_original_op = old_original_op
+ @property
+ def _name_stack(self):
+ # This may be called from a thread where name_stack doesn't yet exist.
+ if not hasattr(self._thread_local, "_name_stack"):
+ self._thread_local._name_stack = ""
+ return self._thread_local._name_stack
+
+ @_name_stack.setter
+ def _name_stack(self, name_stack):
+ self._thread_local._name_stack = name_stack
+
# pylint: disable=g-doc-return-or-yield,line-too-long
@tf_contextlib.contextmanager
def name_scope(self, name):
input: "^ColocateWithMe_2" }
""", gd)
+ def testNameStack(self):
+
+ class NameSettingThread(self.TestThread):
+
+ def run(self):
+ with g.name_scope("foo"):
+ op1 = g.create_op("FloatOutput", [], [dtypes.float32])
+ self.has_mutated_graph.set()
+ self.should_continue.wait()
+ self.should_continue.clear()
+ op2 = g.create_op("FloatOutput", [], [dtypes.float32])
+ self.result = (op1, op2)
+
+ g = ops.Graph()
+ threads = [NameSettingThread(g, i) for i in range(3)]
+ for t in threads:
+ t.start()
+ t.has_mutated_graph.wait()
+ t.has_mutated_graph.clear()
+
+ for t in threads:
+ t.should_continue.set()
+ t.join()
+
+ suffixes = ["", "_1", "_2"]
+ for t, s in zip(threads, suffixes):
+ self.assertEquals("foo" + s + "/FloatOutput", t.result[0].name)
+ self.assertEquals("foo" + s + "/FloatOutput_1", t.result[1].name)
+
@test_util.with_c_api
class ObjectWithName(object):