Helpers for NTP server sync#142
Conversation
Pull Request Test Coverage Report for Build 19747502406Details
💛 - Coveralls |
|
Gets under 1 ms of offset on Mac and around 50 ms on Windows, right after manually syncing with the specified NTP server. Unsure why Windows has such a large offset. |
|
Seems like installing a real NTP client on Windows may solve this. Will try out later. |
| "scikit-video>=1.1.11", | ||
| "scipy>=1.13.0", | ||
| "ntplib>=0.4.0", | ||
| "pillow>=11.0.0,<11.3.0", |
There was a problem hiding this comment.
Why is pillow added here? I don't see it used
There was a problem hiding this comment.
Good catch, don't need it in this PR. Got mixed up while working on this PR (#144) at the same time, trying a bunch of camera-detection stuff that works on Windows too (which I gave up for now).
I think I ended up not needing pillow for this, too, so I will remove it.
|
Can we make this optional? As in the dependencies for NTP are optional. Seems a bit out of scope for general use. |
I don't mind at all if that's better, but is it worth adding a bit of |
|
And I guess syncing is pretty generic. But that said, either way works great for me. |
|
I think it could be pretty simple: make the NTP dependency in an optional dependency group "ntp", and then in that module do like try:
import ntplib
except ImportError as e:
raise ImportError("attempted to import ntp module, but NTP dependencies not installed. Install mio like `pip install mio[ntp]`") from eand then where its used in streamdaq like if {ntp is configured}:
from mio.ntp import ...
# rest of usage |
|
Yes, that's exactly the few lines I was thinking about (tho not |
|
The native Windows time system wasn't accurate, but using Meinberg NTP on Windows keeps this synced within a few milliseconds as well. |
|
Ok now made NTP dependencies optional |
|
maybe a changelog entry? But otherwise lgtm |
|
Also forgot you were syncing windows, maybe that explains why sync couldn't get down into the microsecond range? I remember with the raspis i pretty reliably could get them down there |
|
Thanks, I'll add a changelog before merging.
Yes, the Mac/Raspi sync offset is under a millisecond right after a manual sync. So we can probably get tighter synchronization by increasing the polling frequency. Windows shows more randomness even after manual syncing with a proper NTP client, but it is always under 10 ms, so it's enough for syncing 20-30 FPS imaging systems. |
|
Windows as an OS has bad timing properties generally, the OS loves to preempt stuff in a way that can't be prevented. maybe that goes in the docs |
This pull request adds a module that checks whether the system is synchronized with an optional NTP server. This doesn't perform the actual sync because it's OS-dependent and requires
sudo. Any additions or suggestions are welcome. For instance, I have no idea how to test this.streamcommand).prompt_ntp_syncmethod measures the offset between the system clock and the specified NTP server. This method can be integrated with CLI commands.Example
Add something like below to the CLI command
If the specified NTP server exists and the time is synced, it proceeds:
[25-11-26T10:37:05] INFO [mio.ntp] Checking time sync with NTP server: mio-ntp.local ntp.py:78 [25-11-26T10:37:22] INFO [mio.ntp] Resolved mio-ntp.local to 192.168.10.2 ntp.py:33 INFO [mio.ntp] Time is synchronized with NTP server mio-ntp.local (offset: 0.000s) ntp.py:89And if not, a query shows up:
📚 Documentation preview 📚: https://miniscope-io--142.org.readthedocs.build/en/142/