- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlesson02_num_threads.py
More file actions
Latest commit
19 lines (17 loc) · 545 Bytes
/
Copy pathlesson02_num_threads.py
File metadata and controls
19 lines (17 loc) · 545 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# SuperFastPython.com
# example of setting a large number number of workers
fromtimeimportsleep
fromconcurrent.futuresimportThreadPoolExecutor
# custom task function executed in the thread pool
deftask(number):
# block for a moment
sleep(1)
# report a message
ifnumber%100==0:
print(f'>task {number} done')
# protect the entry point
if__name__=='__main__':
# create a thread pool
withThreadPoolExecutor(1000) asexe:
# issue many tasks to the pool
_=exe.map(task, range(1000))