1 編譯(保留了C和python語言,簡化編譯):
# ./configure --without-java --without-cpp --without-php --without-erlang
#make && make install
2 安裝python thrift模塊
#easy_install thrift
3 生成協議(python)示例來之於http://thrift.apache.org/tutorial/py, 記得第二步中兩個文件都要下載。
#thrift -r --gen c tutorial.thrift
生成了gen-py文件夾,
4 執行驗證 - 示例python腳本下載到thrift-0.9.1/lib/py目錄中,gen-py文件夾也mv過來
# python thrift-server.py
Starting the server...
ping()
add(1,1)
calculate(1, Work(comment=None, num1=1, num2=0, op=4))
calculate(1, Work(comment=None, num1=15, num2=10, op=2))
getStruct(1)
# python thrift-client.py
ping()
1+1=2
InvalidOperation: InvalidOperation(what=4, why='Cannot divide by 0')
15-10=5
Check log: 5
註釋:thrift依賴請查看http://thrift.apache.org/docs/install/, python不依賴特殊的庫(如C++依賴boost),Requirements for building from source提到的依賴可以從搜索引擎查找代碼,編譯就是簡單的./configure && make && make install
操作系統:centos
thrift版本:0.9.1
python: 2.7