fixed python process termination issues on mac and linux (PY-651)

This commit is contained in:
Dmitry Trofimov
2010-09-07 21:08:10 +04:00
parent 6160d0f8e6
commit 2b4b4f3044
3 changed files with 72 additions and 12 deletions
@@ -101,11 +101,7 @@ public abstract class PythonCommandLineState extends CommandLineState {
}
protected ColoredProcessHandler doCreateProcess(GeneralCommandLine commandLine) throws ExecutionException {
return createProcessHandler(commandLine.createProcess(), commandLine);
}
protected ColoredProcessHandler createProcessHandler(Process process, GeneralCommandLine commandLine) throws ExecutionException {
return new ColoredProcessHandler(process, commandLine.getCommandLineString());
return PythonProcessHandler.createProcessHandler(null);
}
public GeneralCommandLine generateCommandLine() throws ExecutionException {
@@ -143,16 +139,22 @@ public abstract class PythonCommandLineState extends CommandLineState {
envs = new HashMap<String, String>(envs);
addPredefinedEnvironmentVariables(envs);
addCommonEnvironmentVariables(envs);
commandLine.setEnvParams(envs);
commandLine.setPassParentEnvs(myConfig.isPassParentEnvs());
}
protected void addCommonEnvironmentVariables(Map<String, String> envs) {
PythonEnvUtil.setPythonUnbuffered(envs);
}
protected void addPredefinedEnvironmentVariables(Map<String, String> envs) {
final PythonSdkFlavor flavor = PythonSdkFlavor.getFlavor(myConfig.getInterpreterPath());
if (flavor != null) {
flavor.addPredefinedEnvironmentVariables(envs);
}
PythonEnvUtil.setPythonUnbuffered(envs);
}
protected void setRunnerPath(GeneralCommandLine commandLine) throws ExecutionException {
@@ -0,0 +1,64 @@
package com.jetbrains.python.run;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.process.ColoredProcessHandler;
import com.intellij.execution.process.RunnerMediator;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.ui.Messages;
import org.jetbrains.annotations.NotNull;
/**
* @author traff
*/
public class PythonProcessHandler extends RunnerMediator.CustomDestroyProcessHandler {
private PythonProcessHandler(@NotNull Process process, @NotNull GeneralCommandLine commandLine, @NotNull String processUid) {
super(process, commandLine, processUid);
}
@Override
protected void detachProcessImpl() {
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
public void run() {
long millis = System.currentTimeMillis();
while (true) {
try {
getProcess().exitValue();
return;
}
catch (IllegalThreadStateException e) {
if (System.currentTimeMillis() - millis > 5000L) {
if (Messages.showYesNoDialog("Do you want to terminate the process?", "Process is not responding", null) == 0) {
killProcess();
return;
}
else {
return;
}
}
}
try {
synchronized (this) {
wait(2000L);
}
}
catch (InterruptedException ignore) {
}
}
}
}
);
super.detachProcessImpl();
}
public static ColoredProcessHandler createProcessHandler(GeneralCommandLine commandLine)
throws ExecutionException {
String processUid = RunnerMediator.injectUid(commandLine);
Process p = commandLine.createProcess();
return new PythonProcessHandler(p, commandLine, processUid);
}
}
@@ -75,12 +75,6 @@ public abstract class PythonTestCommandLineStateBase extends PythonCommandLineSt
return cmd;
}
@Override
protected void addPredefinedEnvironmentVariables(Map<String, String> envs) {
super.addPredefinedEnvironmentVariables(envs);
PythonEnvUtil.setPythonUnbuffered(envs);
}
protected Collection<String> buildPythonPath() {
Collection<String> pythonPathList = Sets.newLinkedHashSet();
pythonPathList.add(PythonHelpersLocator.getHelpersRoot().getPath());