This document is for Kombu's development version, which can be significantly different from previous releases. Get the stable docs here: 5.0.

Logical Clocks and Synchronization - kombu.clocks

Logical Clocks and Synchronization.

class kombu.clocks.LamportClock(initial_value=0, Lock=<built-in function allocate_lock>)[source]

Lamport’s logical clock.

From Wikipedia:

A Lamport logical clock is a monotonically incrementing software counter maintained in each process. It follows some simple rules:

  • A process increments its counter before each event in that process;

  • When a process sends a message, it includes its counter value with the message;

  • On receiving a message, the receiver process sets its counter to be greater than the maximum of its own value and the received value before it considers the message received.

Conceptually, this logical clock can be thought of as a clock that only has meaning in relation to messages moving between processes. When a process receives a message, it resynchronizes its logical clock with the sender.

Usage

When sending a message use forward() to increment the clock, when receiving a message use adjust() to sync with the time stamp of the incoming message.

adjust(other)[source]
forward()[source]
sort_heap(h)[source]

Sort heap of events.

List of tuples containing at least two elements, representing an event, where the first element is the event’s scalar clock value, and the second element is the id of the process (usually "hostname:pid"): sh([(clock, processid, ...?), (...)])

The list must already be sorted, which is why we refer to it as a heap.

The tuple will not be unpacked, so more than two elements can be present.

Will return the latest event.

value = 0

The clocks current value.

class kombu.clocks.timetuple(clock, timestamp, id, obj=None)[source]

Tuple of event clock information.

Can be used as part of a heap to keep events ordered.

Parameters
  • clock (int) – Event clock value.

  • timestamp (float) – Event UNIX timestamp value.

  • id (str) – Event host id (e.g. hostname:pid).

  • obj (Any) – Optional obj to associate with this event.

property clock

itemgetter(item, …) –> itemgetter object

Return a callable object that fetches the given item(s) from its operand. After f = itemgetter(2), the call f(r) returns r[2]. After g = itemgetter(2, 5, 3), the call g(r) returns (r[2], r[5], r[3])

property id

itemgetter(item, …) –> itemgetter object

Return a callable object that fetches the given item(s) from its operand. After f = itemgetter(2), the call f(r) returns r[2]. After g = itemgetter(2, 5, 3), the call g(r) returns (r[2], r[5], r[3])

property obj

itemgetter(item, …) –> itemgetter object

Return a callable object that fetches the given item(s) from its operand. After f = itemgetter(2), the call f(r) returns r[2]. After g = itemgetter(2, 5, 3), the call g(r) returns (r[2], r[5], r[3])

property timestamp

itemgetter(item, …) –> itemgetter object

Return a callable object that fetches the given item(s) from its operand. After f = itemgetter(2), the call f(r) returns r[2]. After g = itemgetter(2, 5, 3), the call g(r) returns (r[2], r[5], r[3])