Example #1
0
        def pyget(self, handler, req, headers = {}):
                printer.info(str(headers))
                printer.info(req)

                try:
                        handler.request('GET', req, headers = headers)
                except  KeyboardInterrupt:
                        return None
                except:
                        printer.critical(format_exc())
                        return None
                try:
                        ack  = handler.getresponse()
                        body = ack.read()
                except  KeyboardInterrupt:
                        return None
                except:
                        printer.critical(format_exc())
                        return None

                key_val = {}
                key_val['body']    = body
                key_val['head']    = str(ack.msg)
                key_val['status']  = ack.status

                printer.info(key_val['head'])
                printer.info(key_val['body'])
                return key_val
Example #2
0
 def main(self):
     try:
         self.do_decode()
     except KeyboardInterrupt:
         pass
     except:
         printer.critical(format_exc())
Example #3
0
 def wait_for_stop(self):
     try:
         self.event_stopped.wait()
     except KeyboardInterrupt:
         pass
     except:
         printer.critical(format_exc())
Example #4
0
 def connect_redis(self):
         try:
                 return StrictRedis(host = self.ip, port = self.port, password = self.passwd, db = self.db)
         except  KeyboardInterrupt:
                 return None
         except:
                 printer.critical(format_exc())
                 return None
Example #5
0
 def get_number(self):
         try:
                 self.event.wait()
         except  KeyboardInterrupt:
                 return None
         except:
                 printer.critical(format_exc())
                 return None
         return self.number
Example #6
0
 def get_image(self):
         ret = None
         try:
                 ret = self.queue_image.get()
         except  KeyboardInterrupt:
                 pass
         except:
                 printer.critical(format_exc())
         return  ret
Example #7
0
 def blk_get_one(self, key, timeout = 0):
         ret = None
         try:
                 ret = self.redis.blpop(key, timeout)[1]
         except  KeyboardInterrupt:
                 pass
         except:
                 printer.critical(format_exc())
         return ret
Example #8
0
 def main(self):
     print('get_channel %d main started' % self.group)
     while True:
         sleep(getsleeptime(self.interval_find_channel))
         try:
             self.do_image()
         except KeyboardInterrupt:
             pass
         except:
             printer.critical(format_exc())
Example #9
0
 def main(self):
     self.udp_format.start()
     self.udp_format.wait_for_start()
     while True:
         if self.flag_stop == True: break
         try:
             self.update_status()
         except KeyboardInterrupt:
             break
         except:
             printer.critical(format_exc())
             sleep(0)
Example #10
0
 def main(self):
     for i in range(self.max_loop):
         try:
             self.do_bid()
         except KeyboardInterrupt:
             break
         except:
             printer.critical(format_exc())
             sleep(0.1)
             continue
         else:
             break
Example #11
0
 def get_number(self):
         ret = None
         try:
                 ret = self.queue_number.get()
         except  KeyboardInterrupt:
                 pass
         except:
                 printer.critical(format_exc())
         if ret == None:
                 return None, None
         sid, number = ret.split(',')
         return  sid, number
Example #12
0
 def wait_for_start(self, timeout=None):
     if timeout == None:
         self.event_started.wait()
     else:
         try:
             int(timeout)
         except KeyboardInterrupt:
             pass
         except:
             printer.critical(format_exc())
             self.event_started.wait(self.default_start_timeout)
         else:
             self.event_started.wait(timeout)
Example #13
0
 def recv_udp(self):
     while True:
         try:
             if self.sock != None:
                 udp_result = self.sock.recvfrom(1500)
         except (timeout, OSError):
             return None
         except:
             printer.critical(format_exc())
             return None
         if self.flag_stop == True:
             return None
         if udp_result[1] == self.server_addr:
             return udp_result[0]
Example #14
0
 def manage_channel(self):
         global pp_global_info
         if pp_global_info.flag_gameover == True:
                 return
         if self.number_onway >= self.max_onway:
                 return
         channel = 'tb0'
         try:
                 maker = [pp_channel_maker(self, 'toubiao', 0, channel), pp_channel_maker(self, 'toubiao', 1, channel)]
         except:
                 printer.critical(format_exc())
                 return
         maker[0].start()
         maker[1].start()
Example #15
0
 def manage_channel(self):
         global channel_center, global_info
         if global_info.flag_create_login != True or global_info.flag_gameover == True:
                 return
         if channel_center.count_login_request <= 0: 
                 return
         if self.number_onway >= self.max_onway:
                 return
         try:
                 maker = [pp_channel_maker(self, 'login', 0, 'login'), pp_channel_maker(self, 'login', 1, 'login')]
         except:
                 printer.critical(format_exc())
                 return
         maker[0].start()
         maker[1].start()
Example #16
0
 def create_channel(self):
         global channel_center, server_dict
         self.manager.maker_in()
         host   = server_dict[self.group][self.server]['ip']
         handle = HTTPSConnection(host)
         handle._http_vsn = 10
         handle._http_vsn_str = 'HTTP/1.0'
         try:
                 handle.connect()
         except  KeyboardInterrupt:
                 pass
         except:
                 printer.critical(format_exc())
         else:
                 channel_center.put_channel(self.channel, self.group, handle)
         self.manager.maker_out()
Example #17
0
 def find_channel(self, channel, group):
         if group == -1:
                 channel_group = 1 if self.queue[0][channel].qsize() <= self.queue[1][channel].qsize() else 0
         else:
                 channel_group = group
         channel_handle_tuple = None
         try:
                 channel_handle_tuple = self.queue[channel_group][channel].get(True, self.timeout_find_channel)
         except  KeyboardInterrupt:
                 return channel_group, None
         except  Empty:
                 return channel_group, None
         except:
                 printer.critical(format_exc())
                 return channel_group, None
         return  channel_group, channel_handle_tuple
Example #18
0
 def manage_channel(self):
         global global_info
         if global_info.flag_create_toubiao[self.id] != True or global_info.flag_gameover == True:
                 return
         if self.number_onway >= self.max_onway:
                 return
         if self.id == 0:
                 channel = 'tb0'
         else:
                 channel = 'tb1'
         try:
                 maker = [pp_channel_maker(self, 'toubiao', 0, channel), pp_channel_maker(self, 'toubiao', 1, channel)]
         except:
                 printer.critical(format_exc())
                 return
         maker[0].start()
         maker[1].start()
Example #19
0
        def update_status(self):
                udp_recv = self.recv_udp()
                if udp_recv == None:
                        return

                udp_recv = self.proto.parse_decode(udp_recv)
                info_val = self.proto.parse_ack(udp_recv)
                if info_val == None:
                        return

                code  = info_val['code']

                if code == 'F':
                        if self.console != None : self.console.update_udp_status(datetime.strftime(datetime.now(), '%H:%M:%S'))
                        return

                bidinfo = info_val['bidinfo']

                if code == 'C':
                        if self.console != None : self.console.update_bid_status(bidinfo)
                        return

                printer.critical(udp_recv)

                ctime = info_val['ltime']
                stime = info_val['systime']
                price = info_val['price']

                try:
                        int_price = int(price)
                except:
                        print_exc()
                        return

                global current_price
                current_price.set(int_price)

                self.check_shot_price(int_price)
                self.check_image_price(int_price, stime)

                if self.console != None :
                        self.console.update_udp_info(ctime, stime, price)
                        self.console.update_bid_status(bidinfo)

                printer.warning(info_val, True)
Example #20
0
    def main(self):
        for i in range(2):
            if self.flag_stop == True: return
            if self.worker.sock != None:
                try:
                    self.worker.format_udp()
                except:
                    printer.critical(format_exc())
            if self.event_stop.wait(1) == True: return

        while True:
            if self.flag_stop == True: return
            if self.worker.sock != None:
                try:
                    self.worker.format_udp()
                except:
                    printer.critical(format_exc())
            if self.event_stop.wait(self.interval) == True: return
Example #21
0
 def find_channel(self, channel, group, timeout = None):
         if group == -1:
                 channel_group = 0 if self.queue[0][channel].qsize() >= self.queue[1][channel].qsize() else 1
         else:
                 channel_group = group
         channel_handle = None
         try:
                 channel_handle = self.queue[channel_group][channel].get(True, timeout)
         except  KeyboardInterrupt:
                 return channel_group, None
         except  Empty:
                 return channel_group, None
         except:
                 printer.critical(format_exc())
                 return channel_group, None
         printer.debug(
                 'fd_channel : login[0] %d login[1] %d , tb0[0] %d tb0[1] %d , tb1[0] %d tb1[1] %d'
                 % (self.queue[0]['login'].qsize(), self.queue[1]['login'].qsize(), self.queue[0]['tb0'].qsize(), self.queue[1]['tb0'].qsize(), self.queue[0]['tb1'].qsize(), self.queue[1]['tb1'].qsize())
                 )
         return  channel_group, channel_handle
Example #22
0
        def pyget(self, handle, req, headers = {}):
                time_req = datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S.%f')

                printer.info(time_req + ' :: ' + str(headers) + ' :: ' + req)

                ack = None

                try:
                        handle.request('GET', req, headers = headers)
                except  KeyboardInterrupt:
                        self.close_handle(handle)
                        return False
                except:
                        printer.critical(format_exc())
                        self.close_handle(handle)
                        return False
                try:
                        ack  = handle.getresponse()
                except  KeyboardInterrupt:
                        self.close_handle(handle)
                        return False
                except:
                        printer.critical(format_exc())
                        self.close_handle(handle)
                        return False

                self.close_handle(handle)

                try:
                        body = ack.read()
                except  KeyboardInterrupt:
                        del(ack)
                        return None
                except:
                        printer.critical(format_exc())
                        del(ack)
                        return None

                key_val = {}
                key_val['head']    = str(ack.msg)
                key_val['status']  = ack.status
                try:
                        key_val['body'] = body.decode('gb18030')
                except:
                        printer.error(body)
                        key_val['body'] = ''

                time_ack = datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S.%f')

                printer.info(time_ack + ' :: ' + str(key_val['head']) + ' :: ' + str(key_val['body']))

                printer.time(time_req + ' --- ' + time_ack + ' :: ' + str(headers) + ' :: ' + req + ' :: ' + str(key_val['head']) + ' :: ' + str(key_val['body']))

                del(ack)
                return key_val
Example #23
0
 def close_handle(self, handle):
         try:
                 handle.close()
                 del(handle)
         except:
                 printer.critical(format_exc())
Example #24
0
 def client_udp(self):
     try:
         self.sock.sendto(self.proto.make_client_req(self.bidno, self.pid),
                          self.server_addr)
     except:
         printer.critical(format_exc())