I feel like I'm being retarded.
-
evt = threading.Event()
timeoffset = (<some datetime in the future> - datetime.datetime.now()).total_seconds()
if not evt.wait(timeoffset):
<do things that depend on that future datetime being less than or equal to right now>
else:
<do different things>Part of me really wants to make that "evt.wait(timeoffset + .1)" to make
100%99% sure it doesn't fire early, but the rest of me wants to slap that part for being a dipshit.
-
How will you know if .1 is the right amount? When you have to ask yourself this question, I believe it means you're doing it wrong.
-
If
evt.wait()
guarantees it does not return false when it returns early¹,timeoffset
should be enough. If it does not, then don't rely on the return value and compare with datetime.datetime.now() again.
¹ Which I don't know. I am not even sure which language you are talking about. But TFM should say.
-
Python, sorry lol. Events return false if the timeout expires before the event is signaled, but I don't know what the rules are for when the timeout actually happens.
Ended up just reworking it so returning early wouldn't be a big deal. It's...worse, but at least it obscures my ignorance.