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

Commit f72ee09

Browse files
comments updated & code logic improvised
ThreadPoolExecutor is replaced with ProcessPoolExecutor to increase execution speed
1 parent 2d59cca commit f72ee09

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

‎c4_troubleshooting_debugging_techniques/m2_slowness/src/retrieve_images_online.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,7 @@ def main():
5151

5252
if __name__ == "__main__":
5353
main()
54+
55+
56+
# NOTE: The ACCESS_KEY is a placeholder for the actual access key that you need to obtain from Unsplash.
57+
# SIDE-NOTE: we can improve the script by adding concurrency to download multiple images simultaneously.

‎c4_troubleshooting_debugging_techniques/m2_slowness/src/thumbnail_generator.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def main():
4949

5050
os.makedirs('thumbnails', exist_ok=True) # create the thumbnail directory
5151

52-
executor = futures.ThreadPoolExecutor()
52+
executor = futures.ProcessPoolExecutor() # alternate: ThreadPoolExecutor()
5353
for root, _, files in os.walk('images'):
5454
for basename in progress_bar(files):
5555
if basename.endswith('.jpg'):
@@ -64,3 +64,7 @@ def main():
6464

6565
if __name__ == "__main__":
6666
sys.exit(main())
67+
68+
69+
# NOTE: here ProcessPoolExecutor() performs better than ThreadPoolExecutor() because of the GIL in Python.
70+
# SIDE-NOTE: GIL might become optional in upcoming Python version (3.13).

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /