multithreading - Python Forcing Subprocess To Fail and Get A Return Code Of Not Zero -


I'm having some trouble using Popen in my Python project basically I have a GUI where the user has a text Can type in widget. When a button is pressed, the text is saved in a new file and then used to pop up to participate in the subprocess as a python file. So basically my GUI works as an IDE for the user's code, press a "run" key, and then the script that is typed as the subprocess.

Everything works fine, though I think how to fight syntax errors in the user's code. I have tried to do something like this:

  p = subprocess.Popen (cmd) p.wait () if p.returncode! = 0: Print ("unsuccessful")   

Expects this program without its code and runs sub-process unless there are no syntax errors, however, The expected behavior of the script that the user is not typed, and the return value is always 0, regardless of the syntax error. I believe that this is probably possible because the thread is implemented correctly, despite what it was in it.

I have also tried to add such things:

  sys.exit (1)   

the script has a specific return The subprocess code is in the code to force it to be excluded with the code, but it still comes back to 0. Then I think this is because sys.exit () only works in the main thread of a program, but I'm not sure.

So basically I'm trying to create a value of 0 based on the value of a subprocess' return code based on zero, on which it is not running correctly because the syntax error user

I would have to open a pipe for that stderr optionally when I popen but I do not really need to read what is the error message of my plan just to bring some kind of generic error message For if something was typed incorrectly.

Thank you very much for reading this, sorry that this is misleading.

Even if you can do this, your users will still see the syntax in your script Hating errors, but not what

therefore forget about subtype and use the built-in function instead:

  script = 'print (0 Try: compile (script, '& lt; string & gt;', 'exec') Except as syntax error: Exceptions with # exceptions Do something ga-friendly ... and: # Syntax looks OK! Run script ...   

'exec' can be fooled by the argument: This specifies only the script's type code. If there are no syntax errors, then compilation returns a.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -