def update_image_decode(self, image, price): try: image = b64decode(image) photo = ImageTk.PhotoImage(Image.open(BytesIO(image))) except: global err_jpg self.lock_image.acquire() self.output_image.image = err_jpg self.output_image['image'] = err_jpg self.output_image.update_idletasks() self.lock_image.release() self.save_jpg(image) logger.error('图片错误,重新请求') else: self.lock_image.acquire() self.output_image.image = photo self.output_image['image'] = photo self.output_last_price['text'] = price self.output_image.update_idletasks() self.lock_image.release() #self.output_last_price.update_idletasks() self.lock_image_price.acquire() self.button_image_price[ 'foreground'] = self.list_image_price_button[-1] self.button_image_price[ 'activeforeground'] = self.list_image_price_button[-1] self.input_image_price.update_idletasks() self.lock_image_price.release()
def price(self, key_val): global proc_ssl_price self.info_val['shot_price'] = self.info_val['last_price'] self.info_val['image_decode'] = key_val['image'] self.event_shot.clear() if self.commander.udp != None: self.commander.udp.reg(self.info_val['shot_price'], self.event_shot) else: logger.error('commander.udp == None') try: arg_val = {} for key in self.info_val: arg_val[key] = self.info_val[key] arg_val['event'] = self.event_shot arg_val['delay'] = 0 arg_val['worker_in'] = self.price_worker_in arg_val['worker_out'] = self.price_worker_out proc_ssl_price.send(arg_val, self.price_ok) except: print_exc() try: arg_val = {} for key in self.info_val: arg_val[key] = self.info_val[key] arg_val['event'] = self.event_shot arg_val['delay'] = 1 arg_val['worker_in'] = self.price_worker_in arg_val['worker_out'] = self.price_worker_out proc_ssl_price.send(arg_val, self.price_ok) except: print_exc()
def proc(self, key_val): try: func = self.func_dict[key_val['cmd']] except KeyError: logger.error('unknow cmd : %s ' % key_val['cmd']) return try: func(key_val) except: print_exc()
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 proc_price_connect(self, p1): self.lock_price_button.acquire() if self.flag_price_button == 'C' or self.flag_price_button == None: self.proc_price_channel_connect() self.flag_price_button = 'S' self.update_price_button('S') elif self.flag_price_button == 'S': self.proc_price_channel_stop() self.flag_price_button = 'C' self.update_price_button('C') else: logger.error('price button status error') self.lock_price_button.release()
def price_ok(self, key_val): if key_val == None: return if 'errcode' in key_val: logger.error('price error! errcode %s , errstring %s' % (key_val['errcode'], key_val['errstring'])) return count = key_val['count'] if count == '1': return self.console.update_first_price(key_val['price']) if count == '2': return self.console.update_second_price(key_val['price']) if count == '3': return self.console.update_third_price(key_val['price']) logger.error('price count error %s' % count)
def login_ok(self, key_val): if key_val == None: return if 'errcode' in key_val: logger.error('login error! errcode %s , errstring %s' % (key_val['errcode'], key_val['errstring'])) return self.lock_login_cb.acquire() self.info_val['pid'] = key_val['pid'] udp_bidno = self.info_val['bidno'] udp_pid = self.info_val['pid'] self.lock_login_cb.release() self.console.update_login_status(key_val['name']) self.console.update_udp_input(udp_bidno, udp_pid)
def image_ok(self, key_val): if key_val == None: return if 'errcode' in key_val: logger.error('image error! errcode %s , errstring %s' % (key_val['errcode'], key_val['errstring'])) return if key_val['image'] == None: logger.error('image error! image decode failed') return self.lock_image_cb.acquire() self.info_val['sid'] = key_val['sid'] self.info_val['last_price'] = key_val['price'] self.lock_image_cb.release() self.console.update_image_decode(key_val['image'], self.info_val['last_price'])
def proc(self, arg): global server_dict flag = [True,True] worker = [None,None] key_val = ({},{}) key_val[0]['host_ip'] = server_dict[0]['toubiao']['ip'] key_val[0]['host_name'] = server_dict[0]['toubiao']['name'] key_val[0]['timeout'] = None key_val[1]['host_ip'] = server_dict[1]['toubiao']['ip'] key_val[1]['host_name'] = server_dict[1]['toubiao']['name'] key_val[1]['timeout'] = None while True: if flag[0] == True: try: worker[0] = self.queue_workers[0].get_nowait() except Empty: flag[0] = False logger.error('ssl_price_sender Queue 0 is empty') except: flag[0] = False print_exc() else: if worker[0].put(arg) == True : flag[0] = False if flag[1] == True: try: worker[1] = self.queue_workers[1].get_nowait() except Empty: flag[1] = False logger.error('ssl_price_sender Queue 1 is empty') except: flag[1] = False print_exc() else: if worker[1].put(arg) == True : flag[1] = False if flag[0] != True and flag[1] != True: return
def proc(self, arg): global server_dict group = arg[0]['group'] key_val = {} key_val['host_ip'] = server_dict[group]['toubiao']['ip'] key_val['host_name'] = server_dict[group]['toubiao']['name'] key_val['timeout'] = None while True: try: worker = self.queue_workers[group].get_nowait() except Empty: logger.error('ssl_image_sender Queue %d is empty' % group) return except: print_exc() return else: if self.last_worker != None : self.last_worker.stop() self.last_worker.close() self.last_worker = worker if worker.put(arg) == True : return
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 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)