I get the following error when I run my code.
Uncaught exception <class 'ValueError'>: I/O operation on closed file.Traceback (most recent call last): File "/home/gidumah/miniconda/envs/ytune/lib/python3.7/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "/home/gidumah/miniconda/envs/ytune/lib/python3.7/runpy.py", line 85, in _run_code exec(code, run_globals) File "/home/gidumah/ytopt/ytopt/ytopt/search/ambs.py", line 128, in <module> search.main() File "/home/gidumah/ytopt/ytopt/ytopt/search/ambs.py", line 105, in main results = list(self.evaluator.get_finished_evals()) File "/home/gidumah/ytopt/ytopt/ytopt/evaluator/evaluate.py", line 200, in get_finished_evals y = future.result() File "/home/gidumah/ytopt/ytopt/ytopt/evaluator/subprocess_evaluator.py", line 41, in result stdout, stderr_data = self.proc.communicate() File "/home/gidumah/miniconda/envs/ytune/lib/python3.7/subprocess.py", line 951, in communicate stdout = self.stdout.read() ValueError: I/O operation on closed file.
我所运行的代码是
subprocess_evaluator.py
,下面给出了这个代码。
class PopenFuture:
FAIL_RETURN_VALUE = Evaluator.FAIL_RETURN_VALUE
def __init__(self, args, parse_fxn):
self.proc = subprocess.Popen(args, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, encoding='utf-8')
self._state = 'active'
self._result = None
self._parse = parse_fxn
def _poll(self):
if not self._state == 'active':
return
retcode = self.proc.poll()
if retcode is None:
self._state = 'active'
stdout, stderr_data = self.proc.communicate()
tmp_res = self._parse(stdout)
if tmp_res != sys.float_info.max:
self._result = tmp_res
elif retcode == 0:
self._state = 'done'
else:
self._state = 'failed'
def result(self):
if self._result is not None:
return self._result
self.proc.wait()
stdout, stderr_data = self.proc.communicate()
if self.done:
self._result = self._parse(stdout)
else:
self._result = self.FAIL_RETURN_VALUE
logger.error(f"Eval failed: {stdout}")
# if stdout:
# print (stdout)#.split('\n')[:-2])#)[:-1])
return self._result
它说错误是在第41行,该行的内容是:stdout, stderr_data = self.proc.communicate()
。
我在沟通电话方面是否有什么地方做得不对?