minimizer.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:distiller 作者: pyoor 项目源码 文件源码
def insert_seeds(self):
        print "[ +D+ ] - Begin seed insertion for minimization"
        bs = beanstalkc.Connection(host='127.0.0.1', port=11300)
        bs.use('min-queue')

        try:
            self.c.execute('''SELECT seed_name FROM results''')
            seeds = self.c.fetchall()
            for seed_name in seeds:
                if not self.is_minimized(seed_name):
                    with open(os.path.join(self.seed_dir, seed_name), 'rb') as d:
                        seed_data = d.read()

                    data = {
                        'name': seed_name,
                        'data': seed_data
                    }

                    seed_pack = msgpack.packb(data, use_bin_type=True)

                    while True:
                        if bs.stats_tube('minimize')['current-jobs-ready'] < 20:
                            print "[ +D+ ] - Pushing seed: %s" % seed_name

                            # Allow 4 hours for minimization - hackish
                            # Fix this later by touching the job after each successful action
                            bs.put(seed_pack, ttr=14400)
                            break
                        else:
                            sleep(1)
        finally:
            bs.close()
            self.sql.close()
            print "[ +D+ ] - All seeds inserted for minimization"
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号