Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Challenge: Parallel File Processing | Multithreading vs. Multiprocessing
Python Structural Programming
Секція 3. Розділ 3
single

single

Challenge: Parallel File Processing

Свайпніть щоб показати меню

In this challenge, you will apply your understanding of Python's threading concepts to simulate a busy coffee shop scenario. Your task is to write a program that brews several coffee orders concurrently using threads. You will leverage parallel execution, referencing the concepts of thread management that you learned in the previous chapter. This challenge will help solidify your grasp of using multithreading to handle multiple tasks simultaneously and ensure proper coordination using thread joining.

Завдання

Проведіть, щоб почати кодувати

You are running a busy coffee shop and need to brew several drinks at once. Write a function that simulates brewing each coffee order in parallel using threads.

  • Implement the brew_coffee(order_name) function so that it simulates brewing by sleeping for 0.2 seconds, then prints a message like Latte is ready! (replace Latte with the actual order name).
  • In brew_all_coffees(orders), start a thread for each coffee order using the brew_coffee function.
  • Make sure the main program waits for all threads to finish before exiting.
  • Use the provided example orders list to test your solution. You should see a message for each coffee order when it is ready.

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 3
single

single

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

some-alt