forked from CoreyMSchafer/code_snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bbcbacc
commit c6e1e77
Showing
34 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import concurrent.futures | ||
import time | ||
|
||
start = time.perf_counter() | ||
|
||
|
||
def do_something(seconds): | ||
print(f'Sleeping {seconds} second(s)...') | ||
time.sleep(seconds) | ||
return f'Done Sleeping...{seconds}' | ||
|
||
|
||
with concurrent.futures.ProcessPoolExecutor() as executor: | ||
secs = [5, 4, 3, 2, 1] | ||
results = executor.map(do_something, secs) | ||
|
||
# for result in results: | ||
# print(result) | ||
|
||
finish = time.perf_counter() | ||
|
||
print(f'Finished in {round(finish-start, 2)} second(s)') |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
|
||
import time | ||
import concurrent.futures | ||
from PIL import Image, ImageFilter | ||
|
||
img_names = [ | ||
'photo-1516117172878-fd2c41f4a759.jpg', | ||
'photo-1532009324734-20a7a5813719.jpg', | ||
'photo-1524429656589-6633a470097c.jpg', | ||
'photo-1530224264768-7ff8c1789d79.jpg', | ||
'photo-1564135624576-c5c88640f235.jpg', | ||
'photo-1541698444083-023c97d3f4b6.jpg', | ||
'photo-1522364723953-452d3431c267.jpg', | ||
'photo-1513938709626-033611b8cc03.jpg', | ||
'photo-1507143550189-fed454f93097.jpg', | ||
'photo-1493976040374-85c8e12f0c0e.jpg', | ||
'photo-1504198453319-5ce911bafcde.jpg', | ||
'photo-1530122037265-a5f1f91d3b99.jpg', | ||
'photo-1516972810927-80185027ca84.jpg', | ||
'photo-1550439062-609e1531270e.jpg', | ||
'photo-1549692520-acc6669e2f0c.jpg' | ||
] | ||
|
||
t1 = time.perf_counter() | ||
|
||
size = (1200, 1200) | ||
|
||
|
||
def process_image(img_name): | ||
img = Image.open(img_name) | ||
|
||
img = img.filter(ImageFilter.GaussianBlur(15)) | ||
|
||
img.thumbnail(size) | ||
img.save(f'processed/{img_name}') | ||
print(f'{img_name} was processed...') | ||
|
||
|
||
with concurrent.futures.ProcessPoolExecutor() as executor: | ||
executor.map(process_image, img_names) | ||
|
||
|
||
t2 = time.perf_counter() | ||
|
||
print(f'Finished in {t2-t1} seconds') |
Binary file added
BIN
+74.2 KB
Python/MultiProcessing/processed/photo-1493976040374-85c8e12f0c0e.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+67.8 KB
Python/MultiProcessing/processed/photo-1504198453319-5ce911bafcde.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+52.9 KB
Python/MultiProcessing/processed/photo-1507143550189-fed454f93097.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+62.3 KB
Python/MultiProcessing/processed/photo-1513938709626-033611b8cc03.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+35.7 KB
Python/MultiProcessing/processed/photo-1516117172878-fd2c41f4a759.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+57.7 KB
Python/MultiProcessing/processed/photo-1516972810927-80185027ca84.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+69.6 KB
Python/MultiProcessing/processed/photo-1522364723953-452d3431c267.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+59.1 KB
Python/MultiProcessing/processed/photo-1524429656589-6633a470097c.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+66.3 KB
Python/MultiProcessing/processed/photo-1530122037265-a5f1f91d3b99.jpg
Oops, something went wrong.
Binary file added
BIN
+53.3 KB
Python/MultiProcessing/processed/photo-1530224264768-7ff8c1789d79.jpg
Oops, something went wrong.
Binary file added
BIN
+23.7 KB
Python/MultiProcessing/processed/photo-1532009324734-20a7a5813719.jpg
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Binary file added
BIN
+46.4 KB
Python/MultiProcessing/processed/photo-1564135624576-c5c88640f235.jpg
Oops, something went wrong.