Commit 6af5c0c7c522a7a629dc10940ac1d38dad0be8b5

Authored by Miguel Barão
1 parent 97c22248
Exists in dev

remove synchronous run_script

Showing 1 changed file with 42 additions and 42 deletions   Show diff stats
aprendizations/tools.py
... ... @@ -20,11 +20,6 @@ logger = logging.getLogger(__name__)
20 20  
21 21  
22 22 # -------------------------------------------------------------------------
23   -# Markdown to HTML renderer with support for LaTeX equations
24   -# -------------------------------------------------------------------------
25   -
26   -
27   -# -------------------------------------------------------------------------
28 23 # Block math:
29 24 # $$x$$ or \begin{equation}x\end{equation}
30 25 # -------------------------------------------------------------------------
... ... @@ -172,43 +167,48 @@ def load_yaml(filename: str, default: Any = None) -> Any:
172 167 # The script is run in another process but this function blocks waiting
173 168 # for its termination.
174 169 # ---------------------------------------------------------------------------
175   -def run_script(script: str,
176   - args: List[str] = [],
177   - stdin: str = '',
178   - timeout: int = 2) -> Any:
179   -
180   - script = path.expanduser(script)
181   - try:
182   - cmd = [script] + [str(a) for a in args]
183   - p = subprocess.run(cmd,
184   - input=stdin,
185   - stdout=subprocess.PIPE,
186   - stderr=subprocess.STDOUT,
187   - text=True, # same as universal_newlines=True
188   - timeout=timeout,
189   - )
190   - except FileNotFoundError:
191   - logger.error(f'Can not execute script "{script}": not found.')
192   - except PermissionError:
193   - logger.error(f'Can not execute script "{script}": wrong permissions.')
194   - except OSError:
195   - logger.error(f'Can not execute script "{script}": unknown reason.')
196   - except subprocess.TimeoutExpired:
197   - logger.error(f'Timeout {timeout}s exceeded while running "{script}".')
198   - except Exception:
199   - logger.error(f'An Exception ocurred running {script}.')
200   - else:
201   - if p.returncode != 0:
202   - logger.error(f'Return code {p.returncode} running "{script}".')
203   - else:
204   - try:
205   - output = yaml.safe_load(p.stdout)
206   - except Exception:
207   - logger.error(f'Error parsing yaml output of "{script}"')
208   - else:
209   - return output
210   -
211   -
  170 +# def run_script(script: str,
  171 +# args: List[str] = [],
  172 +# stdin: str = '',
  173 +# timeout: int = 2) -> Any:
  174 +#
  175 +# script = path.expanduser(script)
  176 +# try:
  177 +# cmd = [script] + [str(a) for a in args]
  178 +# p = subprocess.run(cmd,
  179 +# input=stdin,
  180 +# stdout=subprocess.PIPE,
  181 +# stderr=subprocess.STDOUT,
  182 +# text=True, # same as universal_newlines=True
  183 +# timeout=timeout,
  184 +# )
  185 +# except FileNotFoundError:
  186 +# logger.error(f'Can not execute script "{script}": not found.')
  187 +# except PermissionError:
  188 +# logger.error(f'Can not execute script "{script}": wrong permissions.')
  189 +# except OSError:
  190 +# logger.error(f'Can not execute script "{script}": unknown reason.')
  191 +# except subprocess.TimeoutExpired:
  192 +# logger.error(f'Timeout {timeout}s exceeded while running "{script}".')
  193 +# except Exception:
  194 +# logger.error(f'An Exception ocurred running {script}.')
  195 +# else:
  196 +# if p.returncode != 0:
  197 +# logger.error(f'Return code {p.returncode} running "{script}".')
  198 +# else:
  199 +# try:
  200 +# output = yaml.safe_load(p.stdout)
  201 +# except Exception:
  202 +# logger.error(f'Error parsing yaml output of "{script}"')
  203 +# else:
  204 +# return output
  205 +#
  206 +
  207 +# def run_script(script: str,
  208 +# args: List[str] = [],
  209 +# stdin: str = '',
  210 +# timeout: int = 2) -> Any:
  211 +# asyncio.run(run_script_async(script, args, stdin, timeout))
212 212 # ----------------------------------------------------------------------------
213 213 # Same as above, but asynchronous
214 214 # ----------------------------------------------------------------------------
... ...