Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

How do I use python to alert me when it is time to cut my bread?

I was inspired going through the course with an idea for a simple program. When you make bread you're supposed to wait a while before cutting it. I might have 10 different loaves made at different times. Each needs to cool for an hour and a half. How would I tell python to keep track of my breads and tell me when it is time to cut the bread? Sorry if this is a stupid question. Just curious how difficult this would be. Thank you for your time.

2 Answers

Steven Parker
Steven Parker
229,708 Points

You have a few options, one would be to use the datetime module and sample the current time in a loop until the time you need to ring the bell occurs.

Another is to just pause execution for the amount of time you want to wait before ringing, using the sleep function of the time module.

There are several ways to make a sound, but if you use a Windows machine you might want the winsound module.

Steven Parker
Steven Parker
229,708 Points

Nesting is probably not going to help, and if you are managing multiple alarms you might consider using threading to set up concurrent delays.

Another approach would be to use the original loop suggestion but have it maintain a list of target times for alarms. This type of process is often called scheduling.

Thanks, Steven. I'm experimenting with that right now. This appears to work on a small scale. But here's the thing. I need it to iterate over an ever expanding list of bread. I making bread 12 hours a day at various times throughout the day. I want to be able to add something periodically to the program. How would I set that up in a loop? Maybe I could nest one loop inside another loop to check if anything has been added?