Tachi67 commited on
Commit
3235ba6
·
1 Parent(s): 0648bc7

Update CodeTestingAtomicFlow.py

Browse files
Files changed (1) hide show
  1. CodeTestingAtomicFlow.py +5 -7
CodeTestingAtomicFlow.py CHANGED
@@ -5,12 +5,12 @@ from flow_modules.Tachi67.InterpreterFlowModule import InterpreterAtomicFlow
5
 
6
 
7
  class CodeTestingAtomicFlow(InterpreterAtomicFlow):
8
- def _wait_for_file_update(self, file_location, last_check_time, check_interval=1):
 
9
  while True:
10
- time.sleep(check_interval)
11
- current_time = os.path.getmtime(file_location)
12
- if current_time != last_check_time:
13
  break
 
14
  def _prepare_code_and_lang(self, input_data: Dict[str, Any]):
15
  file_location = input_data["temp_code_file_location"]
16
  input_data["language"] = "python"
@@ -20,7 +20,6 @@ class CodeTestingAtomicFlow(InterpreterAtomicFlow):
20
 
21
  def _check_input(self, input_data: Dict[str, Any]):
22
  assert "temp_code_file_location" in input_data, "temp_code_file_location not passed to CodeTestingAtomicFlow"
23
- assert "temp_code_file_written_timestamp" in input_data, "temp_code_file_written_timestamp not passed to CodeTestingAtomicFlow"
24
 
25
  def _delete_file(self, file_location):
26
  if os.path.exists(file_location):
@@ -31,8 +30,7 @@ class CodeTestingAtomicFlow(InterpreterAtomicFlow):
31
  input_data: Dict[str, Any]):
32
  self._check_input(input_data)
33
  file_loc = input_data["temp_code_file_location"]
34
- last_timestamp = input_data["temp_code_file_written_timestamp"]
35
- self._wait_for_file_update(file_loc, last_timestamp)
36
  self._prepare_code_and_lang(input_data)
37
  self._process_input_data(input_data)
38
  response = self._call()
 
5
 
6
 
7
  class CodeTestingAtomicFlow(InterpreterAtomicFlow):
8
+ def _open_file_and_wait_for_file_update(self, file_location, check_interval=1):
9
+ process = subprocess.Popen(["code", "--wait", file_location])
10
  while True:
11
+ if process.poll() is not None:
 
 
12
  break
13
+ time.sleep(check_interval)
14
  def _prepare_code_and_lang(self, input_data: Dict[str, Any]):
15
  file_location = input_data["temp_code_file_location"]
16
  input_data["language"] = "python"
 
20
 
21
  def _check_input(self, input_data: Dict[str, Any]):
22
  assert "temp_code_file_location" in input_data, "temp_code_file_location not passed to CodeTestingAtomicFlow"
 
23
 
24
  def _delete_file(self, file_location):
25
  if os.path.exists(file_location):
 
30
  input_data: Dict[str, Any]):
31
  self._check_input(input_data)
32
  file_loc = input_data["temp_code_file_location"]
33
+ self._open_file_and_wait_for_file_update(file_loc)
 
34
  self._prepare_code_and_lang(input_data)
35
  self._process_input_data(input_data)
36
  response = self._call()