0

I am new to event-driven programming paradigm and was reading about Twisted.

In this question about Reactor, How does Python's Twisted Reactor work?

 timeout = time_until_next_timed_event()
 events = wait_for_events(timeout)
 events += timed_events_until(now())

logically wouldn't there be a scenario where timeout = time_until_next_timed_event() was computed as 12 Hours, and event = wait_for_events(timeout) just waits for 12 Hours since no external trigger happened and it just missed serving any timed_events_until(now()) events which ideally it could have? Isn't that a compromise?

I am pretty sure I am missing something, can anyone clarify this from a logical perspective?

Community
  • 1
  • 1
Nishant
  • 20,354
  • 18
  • 69
  • 101

1 Answers1

2

If the next timed event is 12 hours from now, then by definition it will be 12 hours until timed_events_until(now()) returns any events.

Nathaniel J. Smith
  • 11,613
  • 4
  • 41
  • 49
  • Thanks for answering! So you mean there is nothing **internal** (anything apart from things it is monitoring **externally**) in this system that can trigger a **timed** event because it is **single threaded** and the **only** job it is doing is **wait** for an external inputs? Then it all makes sense. It is possible that one of those external events could cause a timed event but that will be taken care as part of the **next loop** so that is fine as well. Hope my question makes sense. Please do let me know your thoughts. – Nishant Jan 09 '17 at 05:03
  • An alternate way of asking this is, in a system like this won't there be any Timed Events that happens while you wait - If not why? Is it because the only thing that can do anything is based on an external event (typically a server is driven by client). – Nishant Jan 09 '17 at 16:57
  • 1
    We know when the next timed event will happen (that's what "timed" means, it happens at a particular time). So that's how long we sleep. Why don't you sleep through morning meetings? Because before you go to sleep, you look at your calendar for the next day, and set your alarm clock to go off at an appropriate time. I think this is simpler than you're thinking :-) – Nathaniel J. Smith Jan 10 '17 at 06:42
  • Ok. In that analogy my question is nothing can modify my calendar while I am sleeping :-) I am assuming it is not possible because everything happens in single thread of control. In real life all this is possible ;). And let's imagine a modification to calendar happens, it has to wake you up to do that. Got you! Thanks for answering. – Nishant Jan 10 '17 at 07:04
  • 1
    Right, in this analogy, we imagine that you are the only person who can modify your calendar. (Maybe it's one of those old paper ones you keep in your pocket.) So if someone wants to change the meeting time, then the only way is for them to phone you and wake you up and tell you the new meeting time, and then you modify your calendar. And then before you go back to sleep, you adjust your alarm clock. – Nathaniel J. Smith Jan 10 '17 at 11:19