One function
Timer in jsocol/pystatsd
The author described this change as “Fix timing decorator for async functions”. It counts as a record because the check below fails on the code as it stood at db9424fd4 and passes on 11c3a197b, with nothing else changed between the two runs.
Projectjsocol/pystatsd
Fix saved2022-11-05
Sharing licenceMIT · LICENSE
Change size+11 −0
What the code was meant to do, written into the code itself as a docstring
A context manager/decorator for statsd.timing().
The change
| 11 | 11 | ||
| 12 | 12 | def __call__(self, f): | |
| 13 | 13 | """Thread-safe timing function decorator.""" | |
| 14 | + | if iscoroutinefunction(f): | |
| 15 | + | @safe_wraps(f) | |
| 16 | + | async def _async_wrapped(*args, **kwargs): | |
| 17 | + | start_time = time_now() | |
| 18 | + | try: | |
| 19 | + | return await f(*args, **kwargs) | |
| 20 | + | finally: | |
| 21 | + | elapsed_time_ms = 1000.0 * (time_now() - start_time) | |
| 22 | + | self.client.timing(self.stat, elapsed_time_ms, self.rate) | |
| 23 | + | return _async_wrapped | |
| 24 | + | ||
| 14 | 25 | @safe_wraps(f) | |
| 15 | 26 | def _wrapped(*args, **kwargs): | |
| 16 | 27 | start_time = time_now() |
The check that tells the two apart
fail→pass·statsd/tests.py::test_coroutine_timer_decorator
Check file statsd/tests.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before itdb9424fd4ba9e85e2c36e9cf0a82259cfcc1283c
Broken version dated2022-11-05
Modulestatsd.client.timer
Units changedTimer
Fingerprintc740b06ad9f9c4e7
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.