bpo-36670, regrtest: Fix WindowsLoadTracker() for partial line by vstinner · Pull Request #16550 · python/cpython (original) (raw)

Without access to typeperf's source we're just guessing, but yes, that's how I expect it's working (I suppose the initial "\r\n" might be combined with the timestamp into a single write() call at the start of each sample). As for blank lines this change actually generates more of them (one for every sample) due to the CRLF being at the front of the buffer, but they just get skipped.

I do think there's a third choice, which is just the older behavior (ignore parse issues without a warning). It feels wrong knowing there's a race condition, but it introduces no additional latency and ignoring the partial reads doesn't break anything. That's what's been happening prior to this point anyway.

However, for properly handling partial lines, your approach seems the simplest aside from the latency question (which seems minor as long as the sampling interval remains small). Trying to identify complete lines other than via newline feels like it would be fragile, or need to involve its own latency anyway, such as a timeout.

As for a comment, maybe just after your self._buffer comment, something like:

"typeperf generates CRLF before each sample, rather than after, so this will introduce a SAMPLING_INTERVAL delay"