在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")
其中zk
是KazooClient
有没有更好的方法来验证领导者?
I am able to get current contenders using
election.lock._get_sorted_children()
and respective identifiers usingelection.lock.contenders()
. Butelection.lock.contenders()
also sorts the list, so willelection.lock.contenders()[0]
always be the leader?Note,
election = zk.Election("/path", "uuid")
wherezk
is theKazooClient
Is there any better way to verify the leader?
原文:https://stackoverflow.com/questions/50652758
最满意答案
用户定义的命令挂钩是您正在寻找的:
您可以定义钩子,这是一种特殊的用户定义命令。 每当你运行命令
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 command
hook-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 command
hookpost-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
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
在GDB中,如何从用户定义的命令运行内置命令(In GDB, how do I run a built-in command from a user defined command)[2021-11-07]
用户定义的命令挂钩是您正在寻找的: 您可以定义钩子,这是一种特殊的用户定义命令。 每当你运行命令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 ...
-
GDB逐步执行命令(GDB step over command)[2022-03-19]
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. -
GDB:如何从内置python中更改*便利变量*(GDB: how to change a *convenience variable* from a built-in python)[2022-03-30]
接受一个字符串,返回它的长度 如果你确实需要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 ...