Exemplo n.º 1
0
def init():
    for _ in range(resource):
        thrift_client = ThriftClient.ThriftClient(ip, port, tran, proc,
                                                  timeout)
        client = Service.Client(thrift_client.get_protocol())
        thrift_clients.append(thrift_client)
        clients.put(client)
Exemplo n.º 2
0
def test():
    conn_local = pymongo.Connection()
    db_local = conn_local['tempd']
    thrift_client = ThriftClient.ThriftClient(ip, port, tran, proc, timeout)
    client = Service.Client(thrift_client.get_protocol())
    thrift_client.connect()
    i = 0
    try:
        for news in db_local.tempt.find():
            if i == 0:
                i += 1
                continue
            i += 1
            if i == 12000:
                break


#             thrift_client.connect()
            tit = news['title']
            cont = news['content']
            try:
                tit = str(tit)
                cont = str(cont)
                # tit = 'fadf afdasf'
                # cont = 'fadf fasdfa werwe'
                result = client.get_content_tf(tit, cont)
            #  print tit,result
            except Exception, e:
                print e
                print traceback.format_exc()
                print tit
            #   thrift_client.close()
            #   thrift_client.connect()
    except Exception, e:
        print traceback.format_exc()
Exemplo n.º 3
0
def singal():
    thrift_client = ThriftClient.ThriftClient(ip, port, tran, proc, timeout)
    client = Service.Client(thrift_client.get_protocol())
    thrift_client.connect()
    try:
        tit = "service Calculator extends shared.SharedService"
        cont = '''/**
   * A method definition looks like C code. It has a return type, arguments,
   * and optionally a list of exceptions that it may throw. Note that argument
   * lists and exception lists are specified using the exact same syntax as
   * field lists in struct or exception definitions.
   */

   void ping(),

   i32 add(1:i32 num1, 2:i32 num2),

   i32 calculate(1:i32 logid, 2:Work w) throws (1:InvalidOperation ouch),

   /**
    * This method has a oneway modifier. That means the client only makes
    * a request and does not listen for any response at all. Oneway methods
    * must be void.
    */
   oneway void zip()

}
'''
        try:
            print client.get_content_tf(tit, cont)
        except Exception, e:
            print e
            print tit
            print cont
            thrift_client.close()
            thrift_client.connect()
    finally:
        thrift_client.close()