Skip to content
Snippets Groups Projects
Commit 966a802c authored by Justin Kim's avatar Justin Kim
Browse files

AppDebugJob: Add PYTHONUNBUFFERED variable


Buffered stdout from python script causes that BufferedReader is
waiting infinitely. This change works around not to use buffered
IO for python.

Signed-off-by: default avatarJustin Kim <justin.kim@collabora.com>
Reviewed-by: default avatarGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Differential Revision: https://phabricator.apertis.org/D5375
parent 77c133ce
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,9 @@ import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.Properties;
......@@ -93,13 +96,39 @@ public class AppDebugJob extends Job {
}
args[4] = "--app=" + this.exePath;
args[5] = this.arguments;
/* FIXME: We need "Advanced Preferences" for the Apertis eclipse plugin
* to set environment variables.
*
* https://phabricator.apertis.org/T3299
*
* python uses buffered stdout by default so it can cause infinite waiting
* when BufferedReader tries to read strings. Rather than modifying 'ade'
* not to use buffered stdout (python -u option), this works around to make
* 'ade' print strings immediately.
*
* The below iteration for all existing environment variables is required to
* preserve the values.
*/
List<String> envList = new ArrayList<String>();
Properties envProps = launcher.getEnvironment();
Enumeration<Object> enumProps = envProps.keys();
while (enumProps.hasMoreElements()) {
Object key = enumProps.nextElement();
envList.add(key + "=" + envProps.get(key));
}
envList.add("PYTHONUNBUFFERED=1");
try {
console.start(this.project);
BufferedWriter stdout = new BufferedWriter(new OutputStreamWriter(console.getOutputStream()));
this.process = launcher.execute(new Path("ade"), args, null, location, null);
this.process = launcher.execute(new Path("ade"), args, envList.toArray(new String[envList.size()]), location, null);
stdout.write(launcher.getCommandLine());
stdout.newLine();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment