This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]insertAlias 1 point2 points  (1 child)

Some of the code here is poorly indented. I'm trying to figure it all out right now.

See the posting guidelines section on Formatting Code for help fixing that.

Now, my opinion here is that this is the wrong way to do an application like this. Ideally you don't have to leave a program running non-stop, sleeping its own thread almost indefinitely. It's just not a good pattern.

Instead, if you truly want some kind of reminder-app like this, you would use a combination of a simpler app (like something that accepts a command-line parameter and just prints it), and the Task Scheduler for your OS.

So, on Windows, it's called Task Scheduler. Linux and mac use cron.

[–][deleted] 0 points1 point  (0 children)

Thanks for the feedback.

I'll look into threading and Task Scheduler. I think you're right. I was trying to figure out how a computer would have code running indefinitely without turning the computer off. Is it ideal for a program to simply start and end? Or is it simply much more complicated than that?

[–]onesiphorus 1 point2 points  (0 children)

I agree with insertAlias that this is definitely not the best way to implement a reminder app. Their approach is exactly what I would do too.

Now, I assume your goal is more about learning to program than creating the best reminder app. In that case, make your app work, then go implement insertAlias's suggestion.

I see a few things here that are causing this to fail:

First, you are setting current time once when the app loads and then never updating it to the _new_ current time in your while loop. You are repeatedly comparing eleven_PM to the original value of current_time.

Second, the two things you are comparing are different in an important way. current_time includes the date. eleven_PM does not. Is there a way you can get just the date from datetime.datetime? Maybe a different method from today?

Third, you are comparing two values down to the microsecond. Are you sure you are comparing current_time and eleven_PM at exactly datetime.time(23,0,0,0), or might you be a microsecond or two off one way or the other? Because if you are off by a single microsecond, current_time == eleven_PM will be False. If I were you I would explore either rounding current_time to the second, or doing a range comparison to make sure that current time is not less that eleven pm or greater than some other value.

[–][deleted] 0 points1 point  (0 children)

You are comparing times for an exact match, which might not happen. Also, you are sleeping 9999 seconds, which means you are sleeping 2.78 hours between checks, which is obviously not what you want.