首页 \ 问答 \ 在kazoo获得选举食谱的现任领导(getting current leader of election recipe in kazoo)

在kazoo获得选举食谱的现任领导(getting current leader of election recipe in kazoo)

我能够使用election.lock._get_sorted_children()和使用election.lock._get_sorted_children()相应标识符来获得当前的竞争者。 但是, election.lock.contenders()也会对列表进行排序,所以election.lock.contenders()[0]总是成为领导者吗?

请注意, election = zk.Election("/path", "uuid")其中zkKazooClient

有没有更好的方法来验证领导者?


I am able to get current contenders using election.lock._get_sorted_children() and respective identifiers using election.lock.contenders(). But election.lock.contenders() also sorts the list, so will election.lock.contenders()[0] always be the leader?

Note, election = zk.Election("/path", "uuid") where zk is the KazooClient

Is there any better way to verify the leader?


原文:https://stackoverflow.com/questions/50652758
更新时间:2023-10-19 11:10

最满意答案

用户定义的命令挂钩是您正在寻找的:

您可以定义钩子,这是一种特殊的用户定义命令。 每当你运行命令foo', if the user-defined command hook-foo',那么在该命令之前执行它(没有参数)。

还可以定义一个挂钩,它在您执行的命令之后运行。 每当你运行命令foo', if the user-defined command hookpost-foo',那么在该命令之后执行它(没有参数)。 对于相同的命令,执行后挂钩可以与预执行挂钩同时存在。

此解决方案应该适合您:

define hook-continue
pre_continue
end

define hookpost-continue
post_continue
end

User-defined Command Hooks is what you are looking for:

You may define hooks, which are a special kind of user-defined command. Whenever you run the command foo', if the user-defined commandhook-foo' exists, it is executed (with no arguments) before that command.

A hook may also be defined which is run after the command you executed. Whenever you run the command foo', if the user-defined commandhookpost-foo' exists, it is executed (with no arguments) after that command. Post-execution hooks may exist simultaneously with pre-execution hooks, for the same command.

This solution should work for you:

define hook-continue
pre_continue
end

define hookpost-continue
post_continue
end

相关问答

更多
  • 用户定义的命令挂钩是您正在寻找的: 您可以定义钩子,这是一种特殊的用户定义命令。 每当你运行命令foo', if the user-defined command hook-foo',那么在该命令之前执行它(没有参数)。 还可以定义一个挂钩,它在您执行的命令之后运行。 每当你运行命令foo', if the user-defined command hookpost-foo',那么在该命令之后执行它(没有参数)。 对于相同的命令,执行后挂钩可以与预执行挂钩同时存在。 此解决方案应该适合您: define h ...
  • 您应该在环境变量中添加路径"c:\mingw\bin" 。 这样,无论何时在命令提示符下键入gdb ,它都将从上面的路径进行搜索。 对于valgrind来说也一样吗? 到目前为止,Valgrind无法在Windows平台上运行。 You should add the path "c:\mingw\bin" in your environment variable. This way whenever you type gdb on command prompt, it would search from t ...
  • 我相信你会在这里找到答案: 停止“开发人员工具访问需要控制另一个进程以进行调试以继续”警报 基本上,您可以重新安装Xcode或修复授权数据库。 I believe you will find the answer over here: Stop "developer tools access needs to take control of another process for debugging to continue" alert Basically, you can reinstall Xcode ...
  • 使用GDB Python API中的gdb.selected_inferior().threads()[0].is_running() : $ gdb -q /bin/true (gdb) python from __future__ import print_function (gdb) python print([ t.is_running() for t in gdb.selected_inferior().threads() ]) [True] 参考 GDB Python API: 线程 , In ...
  • si的“step over”类似物被称为nexti (也缩写为ni )。 这将会执行单个汇编指令,但会逐步结束调用。 The "step over" analogue of si is called nexti (also abbreviated ni). This will step a single assembly instruction, but step over calls.
  • 接受一个字符串,返回它的长度 如果你确实需要strlen,你可以使用$_strlen - 一个内置的gdb便利函数来计算字符串长度: (gdb) set $Retrn=$_strlen("test") (gdb) p $Retrn $4 = 4 如何从内置的python中为GDB方便变量赋值? 你可以使用gdb.execute: >more my_own_len.py class my_own_len (gdb.Function): def __init__ (self): super ( ...
  • 有一个很棒的免费工具可以捕获指针,内存分配,解除分配等所有类型的运行时错误,这些错误在编译时无法捕获,所以编译器不会向你发出警告:valgrind http:// valgrind .org / 。 问题是,AFAIK它不能在Windows上运行。 但是,如果您的程序是纯ANSI C,那么您应该能够构建它并在Linux机器上使用valgrind运行它。 我不是百分之百确定它,但它应该在虚拟机中运行正常,所以如果你没有单独的Linux计算机,你可以尝试在Virtual Box或VmWare中安装例如Ubunt ...
  • 据我所知,GDB没有这样的功能。 您可以设置您知道的某个名称的变量,并将其用作“返回”值。 例如,总是像这样设置变量retval : set $retval = 然后,所有新定义的函数都可以将它用作先前调用的函数的返回值。 我知道这只是解决方法,但它相对简单而且有效。 As far as I know GDB does not have such a functionality. You can set a variable of some name that you k ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)