- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlesson02_thread_names.py
More file actions
Latest commit
21 lines (19 loc) · 613 Bytes
/
Copy pathlesson02_thread_names.py
File metadata and controls
21 lines (19 loc) · 613 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# SuperFastPython.com
# example of setting the worker thread name prefix
fromtimeimportsleep
fromconcurrent.futuresimportThreadPoolExecutor
importthreading
# custom task function executed in the thread pool
deftask(number):
# block for a moment
sleep(1)
# protect the entry point
if__name__=='__main__':
# create a thread pool
withThreadPoolExecutor(4,
thread_name_prefix='Downloader') asexe:
# issue many tasks to the pool
_=exe.map(task, range(20))
# report all thread names
forthreadinthreading.enumerate():
print(thread)