def main(): run_queue = Queue(50) processes = [ Process(target=run_task, args=(run_queue, )) for i in range(20) ] for p in processes: p.daemon = True p.start() signal.signal(signal.SIGTERM, SignalTERM) db = getDb() channel_list = db.query( 'SELECT * FROM channel where code="cctv11" ORDER BY id').fetchall() channel_len = len(channel_list) i = 1 for channel in channel_list: while run_queue.full(): # 若任务队列已满,则等待 time.sleep(3) config = channel['config'] try: config = json.loads(config) run_queue.put({'code': channel['code'], 'config': config}) print 'Queue: %s/%s' % (i, channel_len) i = i + 1 except: print 'error' print config for i in range(20): run_queue.put("STOP") for p in processes: p.join()
def main(): run_queue = Queue(50) processes = [Process(target=run_task, args=(run_queue,)) for i in range(20)] for p in processes: p.daemon = True p.start() signal.signal(signal.SIGTERM, SignalTERM) db = getDb() channel_list = db.query('SELECT * FROM channel where where id = 833 ORDER BY id').fetchall() channel_len = len(channel_list) i = 1 for channel in channel_list: while run_queue.full(): # 若任务队列已满,则等待 time.sleep(3) config = channel['config'] try: config = json.loads(config) run_queue.put({'code': channel['code'], 'config': config, 'type': channel['type'], 'province': channel['province'], 'city': channel['city']}) print 'Queue: %s/%s' % (i, channel_len) i = i + 1 except: print 'error' print config for i in range(20): run_queue.put("STOP") for p in processes: p.join()
def __init__(self, channel_code, config, type, province, city): self.channel_code = channel_code self.config = config self.channel_type = [] if type: self.channel_type.append(type) if province: self.channel_type.append(province) if city: self.channel_type.append(city) self.db = getDb() self.init_mongo()
def main(): channel_code = '' for argv in sys.argv: argva = argv.split("=") if (argva[0] == "-channel_id"): channel_code = argva[1] if channel_code == '': print "error" sys.exit() run_queue = Queue(50) processes = [ Process(target=run_task, args=(run_queue, )) for i in range(20) ] for p in processes: p.daemon = True p.start() signal.signal(signal.SIGTERM, SignalTERM) db = getDb() channel_list = db.query('SELECT * FROM channel where id="' + channel_code + '" ORDER BY id').fetchall() channel_len = len(channel_list) i = 1 for channel in channel_list: while run_queue.full(): # 若任务队列已满,则等待 time.sleep(3) config = channel['config'] try: config = json.loads(config) run_queue.put({ 'code': channel['code'], 'config': config, 'type': channel['type'], 'province': channel['province'], 'city': channel['city'] }) print 'Queue: %s/%s' % (i, channel_len) i = i + 1 except: print 'error' print config for i in range(20): run_queue.put("STOP") for p in processes: p.join()
def __init__(self, tvsou_id, name): self.tvsou_id = tvsou_id self.dir_id = self.getDirId() self.name = '' self.oname = '' name = name.decode('gb18030', 'ignore').encode('utf-8') names = name.split(',', 1) self.name = names[0].strip() if len(names) > 1: self.oname = names[1] self.db = getDb() self.wiki_id = '';
def __init__(self, tvsou_id, name): self.tvsou_id = tvsou_id self.dir_id = self.getDirId() self.name = '' self.oname = '' name = name.decode('gb18030', 'ignore').encode('utf-8') names = name.split(',', 1) self.name = names[0].strip() if len(names) > 1: self.oname = names[1] self.db = getDb() self.wiki_id = ''
def __init__(self, channel_code, config): self.channel_code = channel_code self.config = config self.db = getDb() self.init_mongo()
def __init__(self): self.db = getDb() self.init_mongo()
def __init__(self): self.db = getDb() self.init_mongo()
def __init__(self, channel_code, config): self.channel_code = channel_code self.config = config self.db = getDb() self.init_mongo()