首页 \ 问答 \ 如何在thrift python客户端中设置rpc超时?(How to set rpc timeout in thrift python client?)

如何在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
更新时间:2024-03-17 10:03

最满意答案

据推测,您已在构建中包含lib.c ,并在main.c包含#include 。 这导致编译对象(例如, lib.omain.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.clib.c还需要#include "lib.h" ,因此(除其他外)编译器可以检查标头中函数的声明是否与定义匹配。

我还在头部放置了包含警卫。 我会把它作为练习让你去谷歌找出原因。


Presumably, you have included lib.c in your build, as well as #includeing it in main.c. This causes the compiled objects (say, lib.o and main.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) in lib.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).
  • 请注意, _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.
  • 链接器不知道如何定义结构。 或者甚至存在结构。 所有链接器都在关心的是使用外部链接来解析名称,而结构则是编译时的人工制品。 链接器也不知道函数原型。 因此,不知道某个翻译单元中调用的函数的参数是否实际上与该函数期望的参数相对应,并被编译到不同的翻译单元中。 所有链接器都会确保调用调用具有该名称的函数。 所以链接器肯定可以忽略一些错误。 但是这并不能使错误正确。 他们仍然是错误的。 作为程序员,您有责任确保您的程序是正确的,并且一个翻译单元中的结构定义和原型与另一个翻译单元中的结构定义和原型兼容。 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 ...
  • 您在链接命令中列出了两次obj-ia32/ShadowRoutine.o文件。 You have the file obj-ia32/ShadowRoutine.o listed twice in your link command.

相关文章

更多

最新问答

更多
  • 您如何使用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)