Update thread-local singleton example

This commit is contained in:
Roman Mogilatov 2016-08-18 00:59:44 +03:00
parent f27fa60413
commit ac150bb2e4
1 changed files with 18 additions and 17 deletions

View File

@ -25,12 +25,13 @@ example = providers.DelegatedCallable(example,
thread_factory = providers.Factory(threading.Thread,
target=example)
if __name__ == '__main__':
# Create 10 threads for concurrent execution of example():
threads = []
for thread_number in xrange(10):
threads.append(thread_factory(name='Thread{0}'.format(thread_number)))
# Start execution of all create threads:
# Start execution of all created threads:
for thread in threads:
thread.start()
@ -45,5 +46,5 @@ while not queue().empty():
all_objects.add(queue().get())
assert len(all_objects) == len(threads)
# Queue contains same number of objects as number of threads where thread-local
# singleton provider was used.
# Queue contains same number of objects as number of threads where
# thread-local singleton provider was used.