[Twisted-Python] IReactorTime.seconds: epoch time or no?

Tom Most twm at freecog.net
Tue Mar 24 17:05:02 MDT 2020


I'll offer a dissenting opinion:

I've worked on systems where the reactor is patched to use monotonic time. (This is essential on embedded systems that lack a real-time clock.) I'm not aware of this causing any issues, and it fixed real problems.

HTTPFactory is quite unusual in assuming that it is epoch time. Most parts of Twisted that require wall time call `time.time()` or equivalent directly. IMO HTTPFactory is in error here, and this is simply a bug. We should change HTTPFactory to use `time.time()` directly.

Since the time base of IReactorTime.seconds() hasn't ever been clearly defined, I think that we should really go the other way: use `time.monotonic()` by default where possible. (Or, more realistically, make it an option and maybe the default.)

---Tom

On Mon, Mar 23, 2020, at 1:24 PM, Amber Brown (hawkowl) wrote:
> 
> 
> On 24/3/20 6:45 am, Richard van der Hoff wrote:
> > HTTPFactory seems to think that `reactor.seconds` is reliably an epoch 
> > time (see 
> > https://github.com/twisted/twisted/blob/trunk/src/twisted/web/http.py#L3110, 
> > etc).
> > 
> > On the other hand. AsyncioSelectorReactor.seconds() returns a monotonic 
> > time:
> > 
> > python3 -c 'from twisted.internet import asyncioreactor; 
> > print(asyncioreactor.AsyncioSelectorReactor().seconds())'
> > 41116.763594412
> > 
> > One of these is wrong... I think it's HTTPFactory making bad 
> > assumptions, but can anyone confirm the intention here?
> 
> 
> It's a bug in asyncioreactor. IReactorTime defines it as "current time 
> in seconds", which _probably_ should be defined nicer 
> (https://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.IReactorTime.html#seconds) 
> but is generally epoch time.
> 
> asyncioreactor does have a few problems with time:
> 
> https://twistedmatrix.com/trac/ticket/9611
> https://twistedmatrix.com/trac/ticket/9780
> 
> I can't find a bug for this issue, though, although I'm almost sure I've 
> seen it before... so, if you could file one (and maybe a patch to fix 
> it!) then that would be appreciated.
> 
> - Amber
> 
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>



More information about the Twisted-Python mailing list