Browse Source

validate json file for env_config_path when setting context

tags/v1.2.0-rc1
luopengting 4 years ago
parent
commit
003ab3ba84
1 changed files with 8 additions and 3 deletions
  1. +8
    -3
      mindspore/context.py

+ 8
- 3
mindspore/context.py View File

@@ -16,6 +16,7 @@
The context of mindspore, used to configure the current execution environment,
includes the execution mode, execution backend and other feature switches.
"""
import json
import os
import time
import threading
@@ -258,9 +259,13 @@ class _Context:
"""Check and set env_config_path."""
env_config_path = os.path.realpath(env_config_path)
if not os.path.isfile(env_config_path):
raise ValueError("'env_config_path' should be a json file.")
if not os.path.exists(env_config_path):
raise ValueError("The json file set by 'env_config_path' is not exist.")
raise ValueError("The %r set by 'env_config_path' should be an existing json file." % env_config_path)
try:
with open(env_config_path, 'r') as f:
json.load(f)
except (TypeError, ValueError) as exo:
raise ValueError("The %r set by 'env_config_path' should be a json file. "
"Detail: %s." % (env_config_path, str(exo)))
self.set_param(ms_ctx_param.env_config_path, env_config_path)

setters = {


Loading…
Cancel
Save