Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc6e1e77

Browse files
committed
Multiprocessing Snippets
1 parentbbcbacc commitc6e1e77

File tree

34 files changed

+72
-0
lines changed

34 files changed

+72
-0
lines changed
Lines changed: 2 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
importconcurrent.futures
2+
importtime
3+
4+
start=time.perf_counter()
5+
6+
7+
defdo_something(seconds):
8+
print(f'Sleeping{seconds} second(s)...')
9+
time.sleep(seconds)
10+
returnf'Done Sleeping...{seconds}'
11+
12+
13+
withconcurrent.futures.ProcessPoolExecutor()asexecutor:
14+
secs= [5,4,3,2,1]
15+
results=executor.map(do_something,secs)
16+
17+
# for result in results:
18+
# print(result)
19+
20+
finish=time.perf_counter()
21+
22+
print(f'Finished in{round(finish-start,2)} second(s)')
Loading
Loading
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
importtime
3+
importconcurrent.futures
4+
fromPILimportImage,ImageFilter
5+
6+
img_names= [
7+
'photo-1516117172878-fd2c41f4a759.jpg',
8+
'photo-1532009324734-20a7a5813719.jpg',
9+
'photo-1524429656589-6633a470097c.jpg',
10+
'photo-1530224264768-7ff8c1789d79.jpg',
11+
'photo-1564135624576-c5c88640f235.jpg',
12+
'photo-1541698444083-023c97d3f4b6.jpg',
13+
'photo-1522364723953-452d3431c267.jpg',
14+
'photo-1513938709626-033611b8cc03.jpg',
15+
'photo-1507143550189-fed454f93097.jpg',
16+
'photo-1493976040374-85c8e12f0c0e.jpg',
17+
'photo-1504198453319-5ce911bafcde.jpg',
18+
'photo-1530122037265-a5f1f91d3b99.jpg',
19+
'photo-1516972810927-80185027ca84.jpg',
20+
'photo-1550439062-609e1531270e.jpg',
21+
'photo-1549692520-acc6669e2f0c.jpg'
22+
]
23+
24+
t1=time.perf_counter()
25+
26+
size= (1200,1200)
27+
28+
29+
defprocess_image(img_name):
30+
img=Image.open(img_name)
31+
32+
img=img.filter(ImageFilter.GaussianBlur(15))
33+
34+
img.thumbnail(size)
35+
img.save(f'processed/{img_name}')
36+
print(f'{img_name} was processed...')
37+
38+
39+
withconcurrent.futures.ProcessPoolExecutor()asexecutor:
40+
executor.map(process_image,img_names)
41+
42+
43+
t2=time.perf_counter()
44+
45+
print(f'Finished in{t2-t1} seconds')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp