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

逻辑时钟和同步- kombu.clocks

逻辑时钟和同步。

class kombu.clocks.LamportClock(initial_value: int = 0, Lock: type[_thread.allocate_lock] = <built-in function allocate_lock>)[源代码]

兰波特的逻辑时钟。

来自维基百科:

Lamport逻辑时钟是在每个进程中维护的单调递增的软件计数器。它遵循一些简单的规则:

  • 进程在该进程中的每个事件之前递增其计数器;

  • 当进程发送消息时,它将其计数器值包含在消息中;

  • 在接收到消息时,接收方进程将其计数器设置为大于其自身值和接收值的最大值,然后再考虑接收到的消息。

从概念上讲,这个逻辑时钟可以被认为是一个时钟,它只对在进程之间移动的消息有意义。当进程收到消息时,它会将其逻辑时钟与发送方重新同步。

Usage

在发送消息时使用 forward() 要递增时钟,请在接收消息时使用 adjust() 以与传入消息的时间戳同步。

adjust(other: int) int[源代码]
forward() int[源代码]
sort_heap(h: list[tuple[int, str]]) tuple[int, str][源代码]

对一堆事件进行排序。

包含至少两个表示事件的元素的元组列表,其中第一个元素是事件的标量时钟值,第二个元素是进程的id(通常 "hostname:pid" ): sh([(clock, processid, ...?), (...)])

该列表必须已经排序,这就是我们将其称为堆的原因。

元组不会被解包,因此可以存在两个以上的元素。

将返回最新的事件。

value = 0

时钟当前值。

class kombu.clocks.timetuple(clock: int | None, timestamp: float, id: str, obj: Any = None)[源代码]

事件时钟信息的元组。

可用作堆的一部分,以保持事件的有序。

论点:

时钟(可选 [int] ):事件时钟值。Timestamp(Float):事件的Unix时间戳值。Id(Str):事件主机ID(例如 hostname:pid )。Obj(Any):与此事件关联的可选obj。

property clock

Itemgetter(Item,...)-->itemgetter对象

返回一个从其操作数中获取给定项(S)的可调用对象。在f=itemgetter(2)之后,调用f(R)返回r [2] 。在g=itemgetter(2,5,3)之后,调用g(R)返回(r [2] ,r [5] ,r [3] )

property id

Itemgetter(Item,...)-->itemgetter对象

返回一个从其操作数中获取给定项(S)的可调用对象。在f=itemgetter(2)之后,调用f(R)返回r [2] 。在g=itemgetter(2,5,3)之后,调用g(R)返回(r [2] ,r [5] ,r [3] )

property obj

Itemgetter(Item,...)-->itemgetter对象

返回一个从其操作数中获取给定项(S)的可调用对象。在f=itemgetter(2)之后,调用f(R)返回r [2] 。在g=itemgetter(2,5,3)之后,调用g(R)返回(r [2] ,r [5] ,r [3] )

property timestamp

Itemgetter(Item,...)-->itemgetter对象

返回一个从其操作数中获取给定项(S)的可调用对象。在f=itemgetter(2)之后,调用f(R)返回r [2] 。在g=itemgetter(2,5,3)之后,调用g(R)返回(r [2] ,r [5] ,r [3] )