Search in sources :

Example 1 with PyDebugProcess

use of com.jetbrains.python.debugger.PyDebugProcess in project intellij-community by JetBrains.

the class PyDataView method updateTabs.

public void updateTabs(@NotNull ProcessHandler handler) {
    saveSelectedInfo();
    for (TabInfo info : myTabs.getTabs()) {
        PyDataViewerPanel panel = getPanel(info);
        PyFrameAccessor accessor = panel.getFrameAccessor();
        if (!(accessor instanceof PyDebugProcess)) {
            continue;
        }
        boolean shouldBeShown = Comparing.equal(handler, ((PyDebugProcess) accessor).getProcessHandler());
        info.setHidden(!shouldBeShown);
    }
    restoreSelectedInfo(handler);
    if (myTabs.getSelectedInfo() == null) {
        PyFrameAccessor accessor = getFrameAccessor(handler);
        if (accessor != null) {
            addTab(accessor);
        }
    }
}
Also used : PyFrameAccessor(com.jetbrains.python.debugger.PyFrameAccessor) TabInfo(com.intellij.ui.tabs.TabInfo) PyDebugProcess(com.jetbrains.python.debugger.PyDebugProcess)

Example 2 with PyDebugProcess

use of com.jetbrains.python.debugger.PyDebugProcess in project intellij-community by JetBrains.

the class PyDataView method addTab.

private TabInfo addTab(@NotNull PyFrameAccessor frameAccessor) {
    if (hasOnlyEmptyTab()) {
        myTabs.removeTab(myTabs.getSelectedInfo());
    }
    PyDataViewerPanel panel = new PyDataViewerPanel(myProject, frameAccessor);
    TabInfo info = new TabInfo(panel);
    if (frameAccessor instanceof PydevConsoleCommunication) {
        info.setIcon(PythonIcons.Python.PythonConsole);
        info.setTooltipText("Connected to Python Console");
    }
    if (frameAccessor instanceof PyDebugProcess) {
        info.setIcon(AllIcons.Toolwindows.ToolWindowDebugger);
        String name = ((PyDebugProcess) frameAccessor).getSession().getSessionName();
        info.setTooltipText("Connected to debug session '" + name + "'");
    }
    info.setText(EMPTY_TAB_NAME);
    info.setPreferredFocusableComponent(panel.getSliceTextField());
    info.setActions(new DefaultActionGroup(new NewViewerAction(frameAccessor)), ActionPlaces.UNKNOWN);
    info.setTabLabelActions(new DefaultActionGroup(new CloseViewerAction(info, frameAccessor)), ActionPlaces.UNKNOWN);
    panel.addListener(name -> info.setText(name));
    myTabs.addTab(info);
    myTabs.select(info, true);
    return info;
}
Also used : PydevConsoleCommunication(com.jetbrains.python.console.PydevConsoleCommunication) TabInfo(com.intellij.ui.tabs.TabInfo) PyDebugProcess(com.jetbrains.python.debugger.PyDebugProcess)

Example 3 with PyDebugProcess

use of com.jetbrains.python.debugger.PyDebugProcess in project intellij-community by JetBrains.

the class PyDebuggerTask method runTestOn.

public void runTestOn(String sdkHome) throws Exception {
    final Project project = getProject();
    final ConfigurationFactory factory = PythonConfigurationType.getInstance().getConfigurationFactories()[0];
    final RunnerAndConfigurationSettings settings = RunManager.getInstance(project).createRunConfiguration("test", factory);
    myRunConfiguration = (PythonRunConfiguration) settings.getConfiguration();
    myRunConfiguration.setSdkHome(sdkHome);
    myRunConfiguration.setScriptName(getScriptName());
    myRunConfiguration.setWorkingDirectory(myFixture.getTempDirPath());
    myRunConfiguration.setScriptParameters(getScriptParameters());
    new WriteAction() {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            RunManagerEx.getInstanceEx(project).addConfiguration(settings, false);
            RunManagerEx.getInstanceEx(project).setSelectedConfiguration(settings);
            Assert.assertSame(settings, RunManagerEx.getInstanceEx(project).getSelectedConfiguration());
        }
    }.execute();
    final PyDebugRunner runner = (PyDebugRunner) ProgramRunnerUtil.getRunner(getExecutorId(), settings);
    Assert.assertTrue(runner.canRun(getExecutorId(), myRunConfiguration));
    final Executor executor = DefaultDebugExecutor.getDebugExecutorInstance();
    final ExecutionEnvironment env = new ExecutionEnvironment(executor, runner, settings, project);
    final PythonCommandLineState pyState = (PythonCommandLineState) myRunConfiguration.getState(executor, env);
    assert pyState != null;
    pyState.setMultiprocessDebug(isMultiprocessDebug());
    final ServerSocket serverSocket;
    try {
        //noinspection SocketOpenedButNotSafelyClosed
        serverSocket = new ServerSocket(0);
    } catch (IOException e) {
        throw new ExecutionException("Failed to find free socket port", e);
    }
    final int serverLocalPort = serverSocket.getLocalPort();
    final RunProfile profile = env.getRunProfile();
    //turn off exception breakpoints by default
    PythonDebuggerTest.createExceptionBreak(myFixture, false, false, false);
    before();
    setProcessCanTerminate(false);
    myTerminateSemaphore = new Semaphore(0);
    new WriteAction<ExecutionResult>() {

        @Override
        protected void run(@NotNull Result<ExecutionResult> result) throws Throwable {
            myExecutionResult = pyState.execute(executor, runner.createCommandLinePatchers(myFixture.getProject(), pyState, profile, serverLocalPort));
            mySession = XDebuggerManager.getInstance(getProject()).startSession(env, new XDebugProcessStarter() {

                @NotNull
                public XDebugProcess start(@NotNull final XDebugSession session) {
                    myDebugProcess = new PyDebugProcess(session, serverSocket, myExecutionResult.getExecutionConsole(), myExecutionResult.getProcessHandler(), isMultiprocessDebug());
                    StringBuilder output = new StringBuilder();
                    myDebugProcess.getProcessHandler().addProcessListener(new ProcessAdapter() {

                        @Override
                        public void onTextAvailable(ProcessEvent event, Key outputType) {
                            output.append(event.getText());
                        }

                        @Override
                        public void processTerminated(ProcessEvent event) {
                            myTerminateSemaphore.release();
                            if (event.getExitCode() != 0 && !myProcessCanTerminate) {
                                Assert.fail("Process terminated unexpectedly\n" + output.toString());
                            }
                        }
                    });
                    myDebugProcess.getProcessHandler().startNotify();
                    return myDebugProcess;
                }
            });
            result.setResult(myExecutionResult);
        }
    }.execute().getResultObject();
    OutputPrinter myOutputPrinter = null;
    if (shouldPrintOutput) {
        myOutputPrinter = new OutputPrinter();
        myOutputPrinter.start();
    }
    myPausedSemaphore = new Semaphore(0);
    mySession.addSessionListener(new XDebugSessionListener() {

        @Override
        public void sessionPaused() {
            if (myPausedSemaphore != null) {
                myPausedSemaphore.release();
            }
        }
    });
    doTest(myOutputPrinter);
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) PyDebugRunner(com.jetbrains.python.debugger.PyDebugRunner) Semaphore(java.util.concurrent.Semaphore) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result) PyDebugProcess(com.jetbrains.python.debugger.PyDebugProcess) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) PythonCommandLineState(com.jetbrains.python.run.PythonCommandLineState) WriteAction(com.intellij.openapi.application.WriteAction) ProcessEvent(com.intellij.execution.process.ProcessEvent) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) RunProfile(com.intellij.execution.configurations.RunProfile) Project(com.intellij.openapi.project.Project) Key(com.intellij.openapi.util.Key)

Example 4 with PyDebugProcess

use of com.jetbrains.python.debugger.PyDebugProcess in project intellij-community by JetBrains.

the class PyEduDebugRunner method createDebugProcess.

@NotNull
@Override
protected PyDebugProcess createDebugProcess(@NotNull XDebugSession session, ServerSocket serverSocket, ExecutionResult result, PythonCommandLineState pyState) {
    ExecutionConsole executionConsole = result.getExecutionConsole();
    ProcessHandler processHandler = result.getProcessHandler();
    boolean isMultiProcess = pyState.isMultiprocessDebug();
    String scriptName = getScriptName(pyState);
    if (scriptName != null) {
        VirtualFile file = VfsUtil.findFileByIoFile(new File(scriptName), true);
        if (file != null) {
            int line = getBreakpointLineNumber(file, session.getProject());
            if (line != NO_LINE) {
                return new PyEduDebugProcess(session, serverSocket, executionConsole, processHandler, isMultiProcess, scriptName, line + 1);
            }
        }
    }
    LOG.info("Failed to create PyEduDebugProcess. PyDebugProcess created instead.");
    return new PyDebugProcess(session, serverSocket, executionConsole, processHandler, isMultiProcess);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProcessHandler(com.intellij.execution.process.ProcessHandler) ExecutionConsole(com.intellij.execution.ui.ExecutionConsole) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PyDebugProcess(com.jetbrains.python.debugger.PyDebugProcess) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PyDebugProcess (com.jetbrains.python.debugger.PyDebugProcess)4 TabInfo (com.intellij.ui.tabs.TabInfo)2 NotNull (org.jetbrains.annotations.NotNull)2 ConfigurationFactory (com.intellij.execution.configurations.ConfigurationFactory)1 RunProfile (com.intellij.execution.configurations.RunProfile)1 DefaultDebugExecutor (com.intellij.execution.executors.DefaultDebugExecutor)1 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)1 ProcessEvent (com.intellij.execution.process.ProcessEvent)1 ProcessHandler (com.intellij.execution.process.ProcessHandler)1 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)1 ExecutionConsole (com.intellij.execution.ui.ExecutionConsole)1 Result (com.intellij.openapi.application.Result)1 WriteAction (com.intellij.openapi.application.WriteAction)1 Project (com.intellij.openapi.project.Project)1 Key (com.intellij.openapi.util.Key)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PydevConsoleCommunication (com.jetbrains.python.console.PydevConsoleCommunication)1 PyDebugRunner (com.jetbrains.python.debugger.PyDebugRunner)1 PyFrameAccessor (com.jetbrains.python.debugger.PyFrameAccessor)1 PythonCommandLineState (com.jetbrains.python.run.PythonCommandLineState)1