You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

lazy_load.py 1.8 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. """
  2. /**
  3. * Copyright 2020 Zhejiang Lab. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. * =============================================================
  17. */
  18. """
  19. # -*- coding: UTF-8 -*-
  20. from pathlib import Path
  21. from typing import Union
  22. import os
  23. from utils.redis_utils import RedisInstance
  24. from python_io.dictionary_watcher import start_run_watcher
  25. from python_io.logfile_loader import Trace_Thread
  26. class LazyLoad:
  27. def __init__(
  28. self,
  29. run: str,
  30. rundir: Union[str, Path],
  31. ):
  32. self.run = run
  33. self.rundir = rundir
  34. # 惰性加载,在初始化的时候加载目前日志中的所有数据
  35. def init_load(self, uid, cache_path):
  36. # 开启文件监听
  37. start_run_watcher(self.run, str(self.rundir), uid, cache_path)
  38. files = [f for f in self.rundir.glob("*") if f.is_file()]
  39. for file in files:
  40. # 设置每个文件的初始加载状态都为False
  41. # (redis不支持Boolen类型,存为0或1代替)
  42. RedisInstance.set("{}_{}_{}_is_finish".format(uid, self.run,
  43. file.name), 0)
  44. current_size = os.path.getsize(str(file))
  45. Trace_Thread(self.run, file, current_size, uid, cache_path)\
  46. .start()

一站式算法开发平台、高性能分布式深度学习框架、先进算法模型库、视觉模型炼知平台、数据可视化分析平台等一系列平台及工具,在模型高效分布式训练、数据处理和可视分析、模型炼知和轻量化等技术上形成独特优势,目前已在产学研等各领域近千家单位及个人提供AI应用赋能

Contributors (1)