getreadings.py 文件源码

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

项目:riverscope 作者: jamesnunn 项目源码 文件源码
def handle(self, *args, **options):
        # Setup logger with levels and path
        log_path = os.path.join(options['log'], 'riverscope', __name__ + '_log.txt')
        if options['debug']:
            LOG.set_print_handler_level(logging.DEBUG)
            LOG.set_file_handler(log_path, logging.DEBUG)
        else:
            LOG.set_print_handler_level(logging.INFO)
            LOG.set_file_handler(log_path, logging.DEBUG)

        time_start = utils.start_timer()
        pool = ThreadPool(100)
        # TODO http://stackoverflow.com/questions/2632520/what-is-the-fastest-way-to-send-100-000-http-requests-in-python
        results = pool.map(get_readings, zip(Stations.objects.all(), repeat(options['lastn'])))
        clean_results = list(filter(None, results))
        station_readings = [s for sl in clean_results for s in sl]
        with transaction.atomic():
            StationReadings.objects.all().delete()
            StationReadings.objects.bulk_create(station_readings)
        time_diff = utils.end_timer(time_start)
        LOG.info('Added {} readings in {}'.format(len(station_readings), time_diff))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号