python - catch the exception of a subprocess called by another function -


I want to automate a script execution on a subprocess, so I use subprocess lib I am doing thread and schedule lib to schedule it to be created.

I would like to verify that the script executed remotely is working without issues when I give script 1 (error) or when script_file is absent Whoever was trying does not print any error (and if I am not mistaken, by adding exception casing, kills subprocess and its work)

import import import Upprosas Import Multiprocessing Import import schedule import time Functools class MyClass: def catch_exceptions Job_func): @ functools.wraps (job_func) def wrapper (* args, ** kwargs): try: excluding job_func (* args, ** kwargs): Import Traceback Print ("Error") Print (traceback.format_exc ()) Return Cover @catch_exceptions def run (auto, user, host, command): subprocesses. Def (defined by user, host, script_path): schedule.every 0.01) .minutes.do (self.run, user, host, script_path)

All tips are welcome, we do not have INP wrapper target, but there is also a good solution to verify the execution of the defined method.

Use subprocess. POPIN ()

  Run cmd = popon (sCmd, shell = true, stdout = PIPE, stderr = PIPE) in RunCmd.stdout for sLine: print (sLine.decode ( )) Stdout.flush () in aLog.append (sLine.decode ()) for RunCmd.stderr in sLine: print (sLine.decode ()) stderr.flush () aErrorLog append (sLine.decode ()) RunCmd. Wait () RunCmd.returncode == 0: Run RunCmd.wait () else: Run RunCmd.returncode  

RunCmd.wait () Wait for the process to finish, and the process The code will return (for succuss or failure) also prints the output on realtime.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -