Thrift:Python服务器,Erlang客户端错误... {thrift_socket_server,244,{child_error,function_clause,[]}} [英] Thrift: Python Server, Erlang Client Errors... {thrift_socket_server,244,{child_error,function_clause,[]}}

查看:203
本文介绍了Thrift:Python服务器,Erlang客户端错误... {thrift_socket_server,244,{child_error,function_clause,[]}}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这实际上是我第一个关于stackoverflow的问题,但是我遇到了一个我似乎无法解决的问题。我正在制作一个Python服务器,通过节俭来调用erlang客户端。我在节俭中唯一的功能是一个叫做bar,它采用一个整数并打印(整数)。感谢Python客户端,它不是太复杂:

This is actually my first question on stackoverflow, but I've been having a problem that I can't really seem to solve. I'm making a Python server that calls an erlang client through thrift. The only function I've made in thrift is one called bar, which takes in an integer and prints bar (integer). Heres the Python Client, its not too complicated:

#!/usr/bin/env python

import sys
sys.path.append('../gen-py')

from foo import Foo
from foo.ttypes import *
from foo.constants import *

from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol

try:
   # Make socket
   transport = TSocket.TSocket('localhost', 9999)

   # Buffering is critical. Raw sockets are very slow
   transport = TTransport.TBufferedTransport(transport)

   # Wrap in a protocol
   protocol = TBinaryProtocol.TBinaryProtocol(transport)

   # Create a client to use the protocol encoder
   client = Foo.Client(protocol)

   # Connect!
   transport.open()

   msg = client.bar(1452)
   print msg

   transport.close()

except Thrift.TException, tx:
   print "%s" % (tx.message)

这是我的节俭客户端,它正在侦听端口9999:

Here is my thrift client, which is listening on port 9999:

-module(foo_service).

-include("foo_thrift.hrl").
-include("foo_types.hrl").

-export([start_link/0, stop/1,
         handle_function/2,

% Thrift implementations
% FILL IN HERE
         bar/1]).

%%%%% EXTERNAL INTERFACE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

start_link() ->
  thrift_socket_server:start ([{port, get_port()},
                               {name, ?MODULE},
                               {service, foo_thrift},
                               {handler, ?MODULE},
                               {framed, true},
                               {socket_opts, [{recv_timeout, 60*60*1000}]}]).

stop(_Server) ->
  thrift_socket_server:stop (?MODULE),
  ok.

%%%%% THRIFT INTERFACE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

handle_function(Function, Args) when is_atom(Function), is_tuple(Args) ->
  case apply(?MODULE, Function, tuple_to_list(Args)) of
    ok -> ok;
    Reply -> {reply, Reply}
  end.

%%%%% HELPER FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

get_port() ->
  {ok, Result} = application:get_env(foo, service_port),
  Result.

%% ADD THRIFT FUNCTIONS HERE
bar(I) ->
  io:format("bar (~p)~n", [I]).

所以我启动了节俭客户端,从python服务器我调用client.bar(1452) ,不幸的是得到一个孩子错误:

So I start up the thrift client, and from the python server I call client.bar(1452), and unfortunately get a child error:

=CRASH REPORT==== 5-Jul-2013::08:34:32 ===
  crasher:
    initial call: thrift_socket_server:acceptor_loop/1
    pid: <0.51.0>
    registered_name: []
    exception error: no function clause matching 
                     thrift_socket_transport:read({data,#Port<0.1067>,3600000},
                                                  -2147418111) (src/thrift_socket_transport.erl, line 53)
      in function  thrift_transport:read/2 (src/thrift_transport.erl, line 67)
      in call from thrift_framed_transport:read/2 (src/thrift_framed_transport.erl, line 79)
      in call from thrift_transport:read/2 (src/thrift_transport.erl, line 67)
      in call from thrift_binary_protocol:read_data/2 (src/thrift_binary_protocol.erl, line 315)
      in call from thrift_binary_protocol:read/2 (src/thrift_binary_protocol.erl, line 286)
      in call from thrift_binary_protocol:read/2 (src/thrift_binary_protocol.erl, line 175)
      in call from thrift_protocol:read_specific/2 (src/thrift_protocol.erl, line 186)
    ancestors: [foo_service,foo_sup,<0.46.0>]
    messages: []
    links: [<0.48.0>,#Port<0.1067>]
    dictionary: []
    trap_exit: false
    status: running
    heap_size: 987
    stack_size: 27
    reductions: 513
  neighbours:

=ERROR REPORT==== 5-Jul-2013::08:34:32 ===
{thrift_socket_server,244,{child_error,function_clause,[]}}



<任何想法?感谢任何帮助!

Any Ideas? Thanks for any help!

推荐答案

想象出来!当我在我的erlang文件中指定了框架传输时,我正在使用TBufferedTransport。我把它改成了TFramedTrasport,重新编译了我的thrift文件,一切都很好。

Figured it out! I was using TBufferedTransport when I had specified framed transport in my erlang file. I changed it to TFramedTrasport, recompiled my thrift files, and everything worked nicely.

这篇关于Thrift:Python服务器,Erlang客户端错误... {thrift_socket_server,244,{child_error,function_clause,[]}}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆