client = StatsClient() pipe = client.pipeline() pipe.incr('foo') pipe.decr('bar') pipe.timing('baz', 520) pipe.send()
No stats will be sent until
send() is called, at
which point they will be packed into as few UDP packets as possible.
As a Context Manager¶
Pipeline objects can also be used as context managers:
with StatsClient().pipeline() as pipe: pipe.incr('foo') pipe.decr('bar')
Pipeline.send() will be called automatically when the managed block
StatsClient instances are considered thread-safe (or at least
as thread-safe as the standard library’s
Pipeline instances are not thread-safe. Storing stats for later
creates at least two important race conditions in a multi-threaded environment.
You should create one
Pipeline per-thread, if necessary.