def do_proc(self, arg): key_val, callback = arg price = key_val['image_price'] proto = proto_ssl_image(key_val) req = proto.make_image_req(price) head = proto.make_ssl_head(self.host_name) info_val = self.pyget(req, head) #logger.debug(sorted(info_val.items())) if info_val == None: return printer.info(sorted(info_val.items())) if info_val['status'] != 200: logger.error('ack status error : %s' % info_val['status']) printer.error('ack status error : %s' % info_val['status']) try: logger.error(info_val['body'].decode('gb18030')) printer.error(info_val['body'].decode('gb18030')) except: pass else: return try: logger.error(info_val['body'].decode()) printer.error(info_val['body'].decode()) except: pass else: return logger.error('unknow body coding') printer.error(info_val['body']) return ack_sid = proto.get_sid_from_head(info_val['head']) ack_val = proto.parse_image_ack(info_val['body']) ack_val['sid'] = ack_sid ack_val['price'] = price #printer.debug(sorted(ack_val.items())) #logger.debug(sorted(ack_val.items())) logger.debug(ack_sid) if self.flag_stop == True: logger.error( 'image ack recived but thread be stoped. Do not proc callback.' ) return if callback != None: callback(ack_val)
def run(self): if self.thread_info != None: logger.debug( 'Thread %s : Id %s : %s : started' % (self.__class__.__name__, self.ident, self.thread_info)) self.event_started.set() try: self.main() except KeyboardInterrupt: pass if self.thread_info != None: logger.debug( 'Thread %s : Id %s : %s : stoped' % (self.__class__.__name__, self.ident, self.thread_info))
def main(): global pp_config, daemon_udp pp_dns_init() fd_udp_init() account = (pp_config['udp_bidno'], pp_config['udp_pid']) daemon_udp.add(account) daemon_udp.add(account) logger.debug('UDP threads init finished.') daemon_udp.wait_for_stop()
def main(): global daemon_im, daemon_bs, server_udp, UDP_SERVER server_udp = UDPServer(UDP_SERVER, udp_handle) daemon_im = info_maker() daemon_im.start() daemon_im.wait_for_start() daemon_bs = buff_sender() daemon_bs.start() daemon_bs.wait_for_start() daemon_us = udp_server() daemon_us.start() daemon_us.wait_for_start() logger.debug('UDP Server start at %s : %d' % (UDP_SERVER[0], UDP_SERVER[1])) daemon_im.join()
def do_proc(self, arg): key_val, callback = arg proto = proto_ssl_login(key_val) req = proto.make_login_req() head = proto.make_ssl_head(self.host_name) info_val = self.pyget(req, head) logger.debug(sorted(info_val.items())) if info_val == None: return printer.info(sorted(info_val.items())) if info_val['status'] != 200: logger.error('ack status error : %s' % info_val['status']) printer.error('ack status error : %s' % info_val['status']) try: logger.error(info_val['body'].decode('gb18030')) printer.error(info_val['body'].decode('gb18030')) except: pass else: return try: logger.error(info_val['body'].decode()) printer.error(info_val['body'].decode()) except: pass else: return logger.error('unknow body coding') printer.error(info_val['body']) return ack_sid = proto.get_sid_from_head(info_val['head']) ack_val = proto.parse_login_ack(info_val['body']) #ack_val['sid'] = ack_sid #printer.debug(sorted(ack_val.items())) #logger.debug(sorted(ack_val.items())) if callback != None: callback(ack_val)
def logout(self, key_val): logger.debug(key_val.items())
def feedback(self, status, group, worker): logger.debug(worker.info + ' : ' + str(group) + ' : ' + status)
def do_proc(self, arg): key_val, callback = arg price = key_val['shot_price'] image = key_val['image_decode'] sid = key_val['sid'] event = key_val['event'] delay = key_val['delay'] worker_in = key_val['worker_in'] worker_out= key_val['worker_out'] group = self.group worker_in(group) proto = proto_ssl_price(key_val) req = proto.make_price_req(price, image) head = proto.make_ssl_head(self.host_name, sid) int_price = int(price) event.wait() if delay != 0 : sleep(delay) global current_price cur_price = current_price.get() logger.debug('shot_price %d , cur_price %d ' % (int_price, cur_price)) if int_price > cur_price + 300 or int_price < cur_price - 300: worker_out(group) return info_val = self.pyget(req, head) #logger.debug(sorted(info_val.items())) if info_val == None: worker_out(group) return printer.info(sorted(info_val.items())) if info_val['status'] != 200 : logger.error('ack status error : %s' % info_val['status']) printer.error('ack status error : %s' % info_val['status']) try: logger.error(info_val['body'].decode('gb18030')) printer.error(info_val['body'].decode('gb18030')) except: pass else: worker_out(group) return try: logger.error(info_val['body'].decode()) printer.error(info_val['body'].decode()) except: pass else: worker_out(group) return logger.error('unknow body coding') printer.error(info_val['body']) worker_out(group) return ack_sid = proto.get_sid_from_head(info_val['head']) ack_val = proto.parse_price_ack(info_val['body']) #ack_val['sid'] = ack_sid #printer.debug(sorted(ack_val.items())) #logger.debug(sorted(ack_val.items())) worker_out(group) if callback != None : callback(ack_val)