Пример #1
0
 def _loop(self):
     try:
         nt = Network(300,'REP2',self.servers,self.iopool)
         nt = nt.get_socket()
         while True:
             message = nt.recv()
             res = self.process(message)
             nt.send(res)
     except Exception,e:
         logging.exception(e)
Пример #2
0
 def __call__(self,env,response):
     try:
         dheaders = dict(self.default_headers)
         nt = Network(200,'REQ',self.servers,self.iopool)
         nt = nt.get_socket()
         try:
             inputdata = env['wsgi.input'].read()
             env['wsgi.input'] = inputdata
             env['wsgi.errors'].close()
             del env['wsgi.errors']
             nt.send({'env':env})
             res = nt.recv()
         except Exception,e:
             logging.debug('500x0 Internal Server Error')
             logging.error(e)
             
         if not isinstance(res,dict): 
             logging.debug('500x1 Internal Server Error')
             response('500 Internal Server Error', self.default_headers)
             return [json_encode({'error':500,'msg':'Internal Server Error'})]  
         if isinstance(res,dict) and res.has_key('e'):  
             logging.debug('500x2 Internal Server Error: %s' % res['e'])
             response('500 Internal Server Error', self.default_headers)
             return [json_encode({'error':res['e'],'msg':'Worker error'})]  
             
         headers = dheaders
         status  = '200 OK' 
         if isinstance(res,dict) and res.has_key('h'): 
             headers  = res['h']
             for i in xrange(len(headers)):
                 headers[i] = tuple(headers[i]) 
         if isinstance(res,dict) and res.has_key('s'): 
             status   = res['s']
         data         = res['d']
         response(status, headers)
         return [utf8(data[0])]