[Twisted-Python] Intended semantics of IReactorTime.seconds

Glyph glyph at twistedmatrix.com
Sun Mar 27 19:44:44 MDT 2016


> On Mar 26, 2016, at 1:33 PM, Tristan Seligmann <mithrandi at mithrandi.net> wrote:
> 
> Currently, as far as I can tell, all implementations of `IReactorTime.seconds()` (excluding twisted.internet.task.Clock, obviously) are just `time.time()`; IOW, the return value is the number of seconds since the beginning of the UNIX epoch in UTC. Are these the intended semantics? The interface docstring doesn't really make this clear at all.

These are the intended semantics, yes.

> There's some commented out code which suggests the implementation used to be `time.clock()` on win32, which would not satisfy these semantics.

I think you're right, but I believe that was simply a bug based on a misreading of the somewhat confusing documentation of that function at the time.

> (The background for this question is that I'm writing some code which takes an IReactorTime provider for testing purposes, and I'm wondering if I need a separate provider of `datetime.now()` functionality or not)

We really should have a .seconds() wrapper that returns a datetime, yes, since .now() and .utcnow() somewhat subtly are doing I/O.

-glyph





More information about the Twisted-Python mailing list