MCPcopy Create free account
hub / github.com/catboost/catboost / test_threadsafe_singleton

Function test_threadsafe_singleton

library/python/func/ut/test_func.py:139–162  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

137
138
139def test_threadsafe_singleton():
140 class ShouldBeSingle(six.with_metaclass(func.Singleton, object)):
141 def __new__(cls, *args, **kwargs):
142 time.sleep(0.1)
143 return super(ShouldBeSingle, cls).__new__(cls, *args, **kwargs)
144
145 threads_count = 100
146 threads = [None] * threads_count
147 results = [None] * threads_count
148
149 def class_factory(results, i):
150 time.sleep(0.1)
151 results[i] = ShouldBeSingle()
152
153 for i in range(threads_count):
154 threads[i] = threading.Thread(target=class_factory, args=(results, i))
155
156 for i in range(threads_count):
157 threads[i].start()
158
159 for i in range(threads_count):
160 threads[i].join()
161
162 assert len(set(results)) == 1
163
164
165def test_memoize_thread_local():

Callers

nothing calls this directly

Calls 5

lenFunction · 0.85
rangeFunction · 0.50
setFunction · 0.50
startMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected