1. youngking
  2. starry

Commits

zhihu  committed 6b77367

remove gevent

  • Participants
  • Parent commits 7c38cde
  • Branches develop, gevent

Comments (0)

Files changed (2)

File examples/async/client.py

View file
     basic_service = client()
     request = SimpleRequest()
     request.param1 = 'hello, '
-    request.param2 = 'world'
     import time
     t1 = time.time()
     print " --------------  sync test  ----------------"
     for i in range(10):
+        request.param2 = 'world %s'%i
         print basic_service.test(request)
     t2 = time.time()
     print "tested: ", t2 -t1
     print " --------------  fake async test  ----------------"
     for i in range(10):
+        request.param2 = 'world %s'%i
         rpc = basic_service.async.test(request)
         print rpc.response
     t3 = time.time()
     print " --------------  real async test  ----------------"
     results = []
     for i in range(10):
+        request.param2 = 'world %s'%i
         rpc = basic_service.async.test(request)
         results.append(rpc)
     for rpc in results:

File starry/transport.py

View file
 import threading
 
 from gevent.event import AsyncResult
-from . import gevent_zmq as zmq
-#import zmq
+#from . import gevent_zmq as zmq
+import zmq
 
 from protorpc.transport import Transport
 from protorpc.transport import Rpc
         self.socket.send(encoded_request, flags=zmq.NOBLOCK)
 
 
-    def get_response(self, _result):
+    def get_response(self):
         try:
             # receiving
             reply = self.socket.recv()
             #reply = self.socket.recv(zmq.NOBLOCK)
             resp = self._transport.protocol.decode_message(Response,reply)
             if resp.response:
-                _result.set((resp.response,None))
+                return (resp.response,None)
             else:
-                _result.set((None, resp.status))
+                return (None, resp.status)
 
         except AssertionError as e:
             self.socket.setsockopt(zmq.LINGER, 0)
             self.socket.close()
-            _result.set((None, 
-                 RpcStatus(state=remote.RpcState.NETWORK_ERROR,
-                    error_message='Network Error ({0}) : {1}'.format(self.__service_name, e.message))))
+            return None, RpcStatus(state=remote.RpcState.NETWORK_ERROR,
+                             error_message='Network Error ({0}) : {1}'.format(self.__service_name, e.message))
             #except Exception as e:
             #    return None, remote.RpcStatus(state=remote.RpcState.SERVER_ERROR,
             #            error_message='Server Error ({0}) : {1}'.format(self.__service_name, e.message) )
                                         )
         rpc = Rpc(request)
 
-        _result = AsyncResult()
+        #_result = AsyncResult()
 
         def wait_impl():
-            tcp_request.get_response(_result)
-            encoded_response, status = _result.get()
+            encoded_response, status = tcp_request.get_response()
             if status:
                 rpc.set_status(status)
             else: