[An...] Posted June 10, 2021 Share Posted June 10, 2021 We have had an issue with the External Python Interpreter toggling itself off automatically. Has anyone had this happen before? Link to comment Share on other sites More sharing options...
[Sh...] Posted June 29, 2021 Share Posted June 29, 2021 The 2018 external python interpreter option seemed a bit buggy to me as well. Not the checkbox itself but code execution and debugging had some issues. I believe this is why as of 2019 they embedded full python 3.5 interpreter into GOM that allows you to install 3rd party modules while probably allowing them to reduce the chance of conflict with their own GOM interpreter. My solution was to use the subprocess module to call the external python interpreter and pass external scripts and parameters. Many times just wrote to config files from the GOM script then executed a separate script on the external interpreter via subprocess which read the config as a way to pass information. You can use the subprocess.wait() functionality if you need the GOM script to pause until the external interpreter finishes executing. And using the subprocess.communicate() you can have the external script feed info back to the GOM script for printing, error, and logging statements. proc = subprocess.Popen([r"pythonw","path/to/external_script.py"],stdout=subprocess.PIPE, stderr=subprocess.PIPE) out,err = proc.communicate() if err: err = pformat(err.decode('utf-8'),width = 250) log.error(err) messagebox('There was an Error in the external_script.py script.') if out: out = pformat(out.decode('utf-8'),width = 250) log.debug(out) In the above example there is no need to call proc.wait() because communicate will do that. If you don't want output from the external script but need the GOM script to pause until the subprocess is finished then just add proc.wait() after the initial subprocess.Popen call. You don't need to use pformat if you just want to print the output. I just did so for log formatting. I also call the pythonw executable so as to not launch a terminal window during the external script execution. Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in