Search in sources :

Example 6 with KillableColoredProcessHandler

use of com.intellij.execution.process.KillableColoredProcessHandler in project intellij-community by JetBrains.

the class DebuggerManagerImpl method attachVirtualMachine.

@Override
@Nullable
public DebuggerSession attachVirtualMachine(@NotNull DebugEnvironment environment) throws ExecutionException {
    ApplicationManager.getApplication().assertIsDispatchThread();
    DebugProcessEvents debugProcess = new DebugProcessEvents(myProject);
    DebuggerSession session = DebuggerSession.create(environment.getSessionName(), debugProcess, environment);
    ExecutionResult executionResult = session.getProcess().getExecutionResult();
    if (executionResult == null) {
        return null;
    }
    session.getContextManager().addListener(mySessionListener);
    getContextManager().setState(DebuggerContextUtil.createDebuggerContext(session, session.getContextManager().getContext().getSuspendContext()), session.getState(), DebuggerSession.Event.CONTEXT, null);
    final ProcessHandler processHandler = executionResult.getProcessHandler();
    synchronized (mySessions) {
        mySessions.put(processHandler, session);
    }
    if (!(processHandler instanceof RemoteDebugProcessHandler)) {
        // add listener only to non-remote process handler:
        // on Unix systems destroying process does not cause VMDeathEvent to be generated,
        // so we need to call debugProcess.stop() explicitly for graceful termination.
        // RemoteProcessHandler on the other hand will call debugProcess.stop() as a part of destroyProcess() and detachProcess() implementation,
        // so we shouldn't add the listener to avoid calling stop() twice
        processHandler.addProcessListener(new ProcessAdapter() {

            @Override
            public void processWillTerminate(ProcessEvent event, boolean willBeDestroyed) {
                ProcessHandler processHandler = event.getProcessHandler();
                final DebugProcessImpl debugProcess = getDebugProcess(processHandler);
                if (debugProcess != null) {
                    // if current thread is a "debugger manager thread", stop will execute synchronously
                    // it is KillableColoredProcessHandler responsibility to terminate VM
                    debugProcess.stop(willBeDestroyed && !(processHandler instanceof KillableColoredProcessHandler && ((KillableColoredProcessHandler) processHandler).shouldKillProcessSoftly()));
                    // if processWillTerminate() is called from AWT thread debugProcess.waitFor() will block it and the whole app will hang
                    if (!DebuggerManagerThreadImpl.isManagerThread()) {
                        if (SwingUtilities.isEventDispatchThread()) {
                            ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
                                ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true);
                                debugProcess.waitFor(10000);
                            }, "Waiting For Debugger Response", false, debugProcess.getProject());
                        } else {
                            debugProcess.waitFor(10000);
                        }
                    }
                }
            }
        });
    }
    myDispatcher.getMulticaster().sessionCreated(session);
    if (debugProcess.isDetached() || debugProcess.isDetaching()) {
        session.dispose();
        return null;
    }
    if (environment.isRemote()) {
        // optimization: that way BatchEvaluator will not try to lookup the class file in remote VM
        // which is an expensive operation when executed first time
        debugProcess.putUserData(BatchEvaluator.REMOTE_SESSION_KEY, Boolean.TRUE);
    }
    return session;
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) KillableColoredProcessHandler(com.intellij.execution.process.KillableColoredProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) ExecutionResult(com.intellij.execution.ExecutionResult) KillableColoredProcessHandler(com.intellij.execution.process.KillableColoredProcessHandler) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with KillableColoredProcessHandler

use of com.intellij.execution.process.KillableColoredProcessHandler in project intellij-community by JetBrains.

the class BaseJavaApplicationCommandLineState method startProcess.

@NotNull
@Override
protected OSProcessHandler startProcess() throws ExecutionException {
    OSProcessHandler handler = new KillableColoredProcessHandler(createCommandLine());
    ProcessTerminatedListener.attach(handler);
    JavaRunConfigurationExtensionManager.getInstance().attachExtensionsToProcess(getConfiguration(), handler, getRunnerSettings());
    return handler;
}
Also used : OSProcessHandler(com.intellij.execution.process.OSProcessHandler) KillableColoredProcessHandler(com.intellij.execution.process.KillableColoredProcessHandler) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with KillableColoredProcessHandler

use of com.intellij.execution.process.KillableColoredProcessHandler in project intellij-community by JetBrains.

the class PyDebuggerTask method killDebugProcess.

private void killDebugProcess() {
    if (myDebugProcess.getProcessHandler() instanceof KillableColoredProcessHandler) {
        KillableColoredProcessHandler h = (KillableColoredProcessHandler) myDebugProcess.getProcessHandler();
        h.killProcess();
    } else {
        myDebugProcess.getProcessHandler().destroyProcess();
    }
}
Also used : KillableColoredProcessHandler(com.intellij.execution.process.KillableColoredProcessHandler)

Aggregations

KillableColoredProcessHandler (com.intellij.execution.process.KillableColoredProcessHandler)8 NotNull (org.jetbrains.annotations.NotNull)6 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)3 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)3 GoExecutor (com.goide.util.GoExecutor)1 ExecutionException (com.intellij.execution.ExecutionException)1 ExecutionResult (com.intellij.execution.ExecutionResult)1 RunContentExecutor (com.intellij.execution.RunContentExecutor)1 UrlFilter (com.intellij.execution.filters.UrlFilter)1 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)1 ProcessEvent (com.intellij.execution.process.ProcessEvent)1 ProcessHandler (com.intellij.execution.process.ProcessHandler)1 SearchForTestsTask (com.intellij.execution.testframework.SearchForTestsTask)1 Module (com.intellij.openapi.module.Module)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 Key (com.intellij.openapi.util.Key)1 PyPackage (com.jetbrains.python.packaging.PyPackage)1 NonNls (org.jetbrains.annotations.NonNls)1 Nullable (org.jetbrains.annotations.Nullable)1