如何在thrift python客户端中设置rpc超时?(How to set rpc timeout in thrift python client?)
我正在使用thrift编写python客户端,但我找不到任何可用的选项来设置rpc超时。
我的客户端代码如下:
socket = TSocket.TSocket(address, port) transport = TTransport.TBufferedTransport(socket) protocol = TBinaryProtocol.TBinaryProtocol(transport) server = Client.Client(protocol) transport.open()
I'm writing python client using thrift, but I can't find any available option to set rpc time out.
My client code goes below:
socket = TSocket.TSocket(address, port) transport = TTransport.TBufferedTransport(socket) protocol = TBinaryProtocol.TBinaryProtocol(transport) server = Client.Client(protocol) transport.open()
原文:https://stackoverflow.com/questions/12034768
最满意答案
据推测,您已在构建中包含
lib.c
,并在main.c
包含#include
。 这导致编译对象(例如,lib.o
和main.o
)各自具有函数的定义。 链接器选择它(因为它检查所有目标文件,而编译器一次生成一个,因此无法检测两个或多个对象文件多次定义的实例)并抱怨多个定义。作为指导原则,永远不要
#include
.c
文件。相反,将函数的声明(也称为原型)放在头文件中(比如
lib.h
)#ifndef LIB_H_INCLUDED #define LIB_H_INCLUDED #include "defs.h" void getUserName(); void getCourse (index); // etc #endif
和
#include
在每个需要使用这些函数的.c
文件中。 这提供了足够的信息,因此编译器可以检查您是否正确调用函数。 然后将函数定义(也就是它们的实现)放在lib.c
。lib.c
还需要#include "lib.h"
,因此(除其他外)编译器可以检查标头中函数的声明是否与定义匹配。我还在头部放置了包含警卫。 我会把它作为练习让你去谷歌找出原因。
Presumably, you have included
lib.c
in your build, as well as#include
ing it inmain.c
. This causes the compiled objects (say,lib.o
andmain.o
) to each have definitions of the functions. The linker picks this up (since it examines all the object files, whereas the compiler produces one at a time, so cannot detect instances where two or more objects files define something more than once) and complains about multiple definitions.As a guideline, never
#include
a.c
file.Instead, place declarations (aka prototypes) of your functions in a header file (say
lib.h
)#ifndef LIB_H_INCLUDED #define LIB_H_INCLUDED #include "defs.h" void getUserName(); void getCourse (index); // etc #endif
and
#include
that in every.c
file that needs to use the functions. This provides enough information so the compiler can check if you are calling the functions correctly. Then place the function definitions (aka their implementations) inlib.c
.lib.c
will also need to#include "lib.h"
, so (among other things) the compiler can check if the declarations of the functions from the header match the definitions.I've also placed include guards in the header. I'll leave it as an exercise for you to google to work out why.
相关问答
更多-
当您输入日期时,您的程序会崩溃,因为您将dp->month , dp->day和dp->year的值传递给scanf() 。 scanf()需要一个指针来存储结果; 在C中,整数看起来像一个指针,所以它很乐意尝试将dp->month的unitialized值解释为指针,并因为无法在那里写入而崩溃。 您想要使用&dp->month等。 我建议编译所有警告启用(我不知道Dev-C ++,但GCC标志是-Wall -Wextra ); 我还建议处理有关错误的警告,因此您不能使用-Werror意外忽略它们。 如果我 ...
-
全局变量可以包含任意数量的声明 ,但只能包含一个定义 。 初始化程序使它成为一个定义,所以它会抱怨有两个(即使他们同意)。 A global variable can have any number of declarations, but only one definition. An initializer makes it a definition, so it will complain about having two of those (even if they agree).
-
另一个链接器问题(Yet another linker issue)[2022-03-25]
请注意, _HEADER_H是C ++用户代码中的非法名称 - 以下划线开头的名称和大写字母是为C ++实现保留的。 这通常不会引起明显的问题,但是当您在此上下文中使用可能是HEADER等实现中的常用名称时,它很可能。 The problem was in a multi-installation of MinGW. I had one already installed, and when I got Qt on my computer, it had installed it's own MinGW. ... -
尝试在您的vc \ bin目录中使用undname.exe。 它不适合我的字符串,但也许你正在使用不同版本的visual studio--我使用的是2008。 Try using undname.exe in your vc\bin dir. It didn't work for me on your strings but maybe you are using a different version of visual studio - I'm using 2008.
-
是否允许链接器忽略两个结构定义不相等?(Is the linker allowed to ignore that two struct definitions are not equal?)[2022-04-10]
链接器不知道如何定义结构。 或者甚至存在结构。 所有链接器都在关心的是使用外部链接来解析名称,而结构则是编译时的人工制品。 链接器也不知道函数原型。 因此,不知道某个翻译单元中调用的函数的参数是否实际上与该函数期望的参数相对应,并被编译到不同的翻译单元中。 所有链接器都会确保调用调用具有该名称的函数。 所以链接器肯定可以忽略一些错误。 但是这并不能使错误正确。 他们仍然是错误的。 作为程序员,您有责任确保您的程序是正确的,并且一个翻译单元中的结构定义和原型与另一个翻译单元中的结构定义和原型兼容。 C不会成为 ... -
您的第二个示例明显且易于诊断违反了一个定义规则。 它有两个带有外部链接的非内联函数的定义。 链接器很容易诊断,因为从链接的目标文件中包含的函数名称可以明显看出违规。 您的第一个示例以更微妙的方式打破了一个定义规则。 因为类体中定义的函数是inline隐式声明的,所以必须检查函数体以确定违反了一个定义规则 。 仅仅因为这个原因,我并不感到惊讶,你的实施没有发现违规(我没有第一次)。 显然,在单独查看一个源文件时,编译器无法发现违规,但可能是检测到违规和链接时间的信息实际上并不存在传递给链接器的目标文件。 它肯 ...
-
据推测,您已在构建中包含lib.c ,并在main.c包含#include 。 这导致编译对象(例如, lib.o和main.o )各自具有函数的定义。 链接器选择它(因为它检查所有目标文件,而编译器一次生成一个,因此无法检测两个或多个对象文件多次定义的实例)并抱怨多个定义。 作为指导原则,永远不要#include .c文件。 相反,将函数的声明(也称为原型)放在头文件中(比如lib.h ) #ifndef LIB_H_INCLUDED #define LIB_H_INCLUDED #include ...
-
我猜测链接器没有抱怨,因为它不知道它正在发生。 当您在翻译单元中编译函数模板的特定实例时,这些函数被标记为弱符号(使用ELF术语); 当链接器看到具有相同签名的多个弱符号时,它将删除除一个定义之外的所有符号。 C ++标准要求内联/模板函数的多个定义是相同的 - 着名的一个定义规则。 这就是应始终在头文件中定义模板和内联函数的原因。 链接器无需实际检查函数定义是否相同 - 它假定您已遵守规则,因此可以选择其中任何一个。 在这种情况下,它选择输出55的版本,但它可以很容易地选择另一个。 在任何情况下,您通过提 ...
-
这个pragma不应该阻止这个吗? 不,在这种情况下,如果此头文件包含在多个位置,则会创建someVariable的多个定义。 如果Bh和Ch都包含你的头文件,那么将创建两个someVariable。 更好的方法是只在一个.cpp文件中定义变量,在其他地方使用extern 。 Shouldn't the pragma prevent this too? No, in this case multiple definitions of someVariable will be created if this ...
-
当nm只看到一个定义时,为什么“多个定义链接器错误”(Why “Multiple definitions linker error” when nm only sees one definition)[2022-01-08]
您在链接命令中列出了两次obj-ia32/ShadowRoutine.o文件。 You have the file obj-ia32/ShadowRoutine.o listed twice in your link command.