os_env_config.py 842 B

123456789101112131415161718192021222324252627282930
  1. import os
  2. def get_op_num_threads(env_name: str) -> int:
  3. env_value = os.getenv(env_name, None)
  4. return get_value_from_string(env_value, -1)
  5. def get_load_images_timeout() -> int:
  6. env_value = os.getenv('MINERU_PDF_RENDER_TIMEOUT', None)
  7. return get_value_from_string(env_value, 300)
  8. def get_value_from_string(env_value: str, default_value: int) -> int:
  9. if env_value is not None:
  10. try:
  11. num_threads = int(env_value)
  12. if num_threads > 0:
  13. return num_threads
  14. except ValueError:
  15. return default_value
  16. return default_value
  17. if __name__ == '__main__':
  18. print(get_value_from_string('1', -1))
  19. print(get_value_from_string('0', -1))
  20. print(get_value_from_string('-1', -1))
  21. print(get_value_from_string('abc', -1))
  22. print(get_load_images_timeout())