Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
wall clock timing functionality #173
This is probably fairly low priority, but: an interesting and sometimes-useful feature is the ability to sleep until a particular wall clock time (e.g., "this cert is expiring at 2017-12-31T12:00:00Z, so I want to wake up 3 days before that so I can renew it"). This is quite different from trio's current timekeeping abilities, which are all oriented around monotonic time (which ignores clock changes, and stops while the computer is suspended, etc.). Really these are just different incommensurable time scales.
Fortunately, I don't think we need the ability to directly set a cancel scope deadline to a particular wall clock time, so this doesn't need to be integrated deep into the guts of trio's run loop. I think it'd be sufficient to provide a
This comment and the replies have some more details on this idea, including notes on how it could be implemented on different systems.
The discussion in #394 got me thinking about this a bit again.
Contrary to the discussion in #168, it looks like on MacOS the best way to do this is not
On Linux, it isn't 100% clear to me how a
I guess the more interesting use case for a clock being stepped is if you have a timer set to "every Saturday at noon" -- in this case if the timer is currently set to the next Saturday – like say it's 2018-01-01, so the timer is set to 2018-01-06 – and then the clock is stepped backwards to 2017-01-01, you don't want to keep sleeping until 2018-01-6, you want to redo the "next Saturday" calculation and reset the timer to a different date (!). Clock change notification is also possible on MacOS by fiddling with Mach ports, as noted here. libdispatch is open source, so you can look at how they do this:
Brainstorming possible tr- + time-themed names for a trio wall-clock library:
Though most of the discussion in that twisted ticket seems to be about how to untangle themselves from having decided early on to use a mix of monotonic and wall-clock time. (Not really their fault, but they're using wall clock time for calculations, and then calling