mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed python process termination issues on mac and linux (PY-651)
This commit is contained in:
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user