Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot debug Python code in PyCharm #2093

Closed
vmax opened this issue Sep 22, 2020 · 7 comments
Closed

Cannot debug Python code in PyCharm #2093

vmax opened this issue Sep 22, 2020 · 7 comments
Assignees
Labels
awaiting-maintainer Awaiting review from Bazel team on issues lang: python Python rules integration os: linux Linux support product: PyCharm PyCharm plugin topic: debugging Issues related to debugging type: bug

Comments

@vmax
Copy link

vmax commented Sep 22, 2020

Description

Currently, it's impossible to debug py_binary/py_test in PyCharm; this is a sample exception message:

/usr/bin/setsid --wait /usr/bin/python3.8 /snap/pycharm-community/205/plugins/python-ce/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 46541 --file /home/vmax/.cache/bazel/_bazel_vmax/379e6d40d9b6adee7e2caab387d392a8/execroot/__main__/bazel-out/k8-fastbuild/bin/test
pydev debugger: process 80673 is connecting

Connected to pydev debugger (build 201.8743.11)
Fatal Python error: init_sys_streams: can't initialize sys standard streams
Python runtime state: core initialized
Traceback (most recent call last):
  File "/usr/lib/python3.8/io.py", line 78, in <module>
    class BufferedIOBase(_io._BufferedIOBase, IOBase):
  File "/usr/lib/python3.8/abc.py", line 85, in __new__
    cls = super().__new__(mcls, name, bases, namespace, **kwargs)
KeyboardInterrupt

Process finished with exit code 1

What's curious is that with every debug rerun it's having a different stack trace (KeyboardInterrupt is always the last element)

Reproducible example

BUILD:

py_binary(
    name = "test",
    srcs = ["test.py"],
)

test.py:

import sys
print(sys.path)

Configuration

OS: Ubuntu 20.04
PyCharm version: pycharm-community (2020.1/stable); installed via Snap
Python: 3.8.2
Plugin version: reproduced both on latest released version (2020.07.13.0.2) and one built from latest master (commit sha 43c4949a35bcde233c2f1b9bd2c6ecfdfa93acb6)

@vinayan3
Copy link

An older PyCharm bug indicated that switching on Attaching to subprocess automatically while debugging is an issue.

https://intellij-support.jetbrains.com/hc/en-us/community/posts/360003290559-KeyboardInterrupt-when-debugging-a-PyTorch-project

I tried turning this off and then the debugger says that it cannot debug because the main process has a subprocess.

@cwaeland
Copy link

I'm experiencing this the issue as well and would love to hear if there's a possible workaround. I cross posted on the Bazel slack as well.

@sseveran
Copy link

sseveran commented Nov 3, 2020

I have to manually update pydevd. Explanation here: #402

@PoncinMatthieu
Copy link

See this comment for a fix with latest bazel version and latest intellij: #402 (comment)

@mai93 mai93 added topic: debugging Issues related to debugging os: linux Linux support lang: python Python rules integration type: bug labels Feb 11, 2021
@therearesomewhocallmetim
Copy link

therearesomewhocallmetim commented Aug 15, 2022

Has there been any progress on this issue? I'm in 2022 on PyCharm 2022.2 and Bazel plugin 2022.08.09.0.1-api-version-222, but debugging doesn't work either

UPD: I had a closer look at the output, turns out, I updated PyCharm after I got the first error (as in the topic description), and when I got an error after the update, I assumed it was the same. But it isn't. Here's what I am getting now:

java.lang.Throwable: 'Application.acquireReadActionLock' is deprecated and going to be removed soon. Use `runReadAction()` instead
	at com.intellij.openapi.diagnostic.Logger.error(Logger.java:184)
	at com.intellij.diagnostic.PluginException.reportDeprecatedUsage(PluginException.java:105)
	at com.intellij.openapi.application.impl.ApplicationImpl.acquireReadActionLock(ApplicationImpl.java:1184)
	at com.google.idea.blaze.python.run.BlazePyPositionConverter.convertLocalLineToRemote(BlazePyPositionConverter.java:111)
	at com.google.idea.blaze.python.run.BlazePyPositionConverter.convertToPython(BlazePyPositionConverter.java:65)
	at com.jetbrains.python.debugger.AbstractLineBreakpointHandler.registerBreakpoint(AbstractLineBreakpointHandler.java:39)
	at com.jetbrains.python.debugger.AbstractLineBreakpointHandler.registerBreakpoint(AbstractLineBreakpointHandler.java:16)
	at com.intellij.xdebugger.impl.XDebugSessionImpl.handleBreakpoint(XDebugSessionImpl.java:434)
	at com.intellij.xdebugger.impl.XDebugSessionImpl.processBreakpoints(XDebugSessionImpl.java:419)
	at com.intellij.xdebugger.impl.XDebugSessionImpl.processAllBreakpoints(XDebugSessionImpl.java:575)
	at com.intellij.xdebugger.impl.XDebugSessionImpl.initBreakpoints(XDebugSessionImpl.java:314)
	at com.intellij.xdebugger.impl.XDebugSessionImpl.init(XDebugSessionImpl.java:282)
	at com.intellij.xdebugger.impl.XDebuggerManagerImpl.startSession(XDebuggerManagerImpl.java:280)
	at com.intellij.xdebugger.impl.XDebuggerManagerImpl.startSession(XDebuggerManagerImpl.java:232)
	at com.jetbrains.python.debugger.PyDebugRunner.createXDebugSession(PyDebugRunner.java:163)
	at com.jetbrains.python.debugger.PyDebugRunner.doExecute(PyDebugRunner.java:249)
	at com.google.idea.blaze.python.run.BlazePyDebugRunner.doExecute(BlazePyDebugRunner.java:81)
	at com.jetbrains.python.debugger.PyDebugRunner.lambda$executeWithLegacyWorkaround$11(PyDebugRunner.java:302)
	at com.intellij.openapi.application.constraints.ConstrainedTaskExecutor.lambda$submit$4(ConstrainedTaskExecutor.java:64)
	at com.intellij.openapi.application.constraints.BaseConstrainedExecution$Companion$scheduleWithinConstraints$1.invoke(BaseConstrainedExecution.kt:68)
	at com.intellij.openapi.application.constraints.BaseConstrainedExecution$Companion.scheduleWithinConstraints(BaseConstrainedExecution.kt:71)
	at com.intellij.openapi.application.constraints.BaseConstrainedExecution.scheduleWithinConstraints(BaseConstrainedExecution.kt:38)
	at com.intellij.openapi.application.impl.BaseExpirableExecutorMixinImpl.access$scheduleWithinConstraints$s1153900543(BaseExpirableExecutorMixinImpl.kt:12)
	at com.intellij.openapi.application.impl.BaseExpirableExecutorMixinImpl$scheduleWithinConstraints$$inlined$Runnable$1.run(Runnable.kt:19)
	at com.intellij.openapi.application.impl.AppUIExecutorImpl$MyEdtExecutor.execute(AppUIExecutorImpl.kt:72)
	at com.intellij.openapi.application.impl.BaseExpirableExecutorMixinImpl.scheduleWithinConstraints(BaseExpirableExecutorMixinImpl.kt:23)
	at com.intellij.openapi.application.constraints.ConstrainedTaskExecutor.submit(ConstrainedTaskExecutor.java:62)
	at com.intellij.openapi.application.impl.BaseExpirableExecutorMixinImpl.submit(BaseExpirableExecutorMixinImpl.kt:30)
	at com.jetbrains.python.debugger.PyDebugRunner.executeWithLegacyWorkaround(PyDebugRunner.java:302)
	at com.jetbrains.python.debugger.PyDebugRunner.lambda$execute$10(PyDebugRunner.java:275)
	at com.intellij.execution.impl.ExecutionManagerImpl$startRunProfile$1.invoke(ExecutionManagerImpl.kt:173)
	at com.intellij.execution.impl.ExecutionManagerImpl$startRunProfile$1.invoke(ExecutionManagerImpl.kt:72)
	at com.intellij.execution.impl.ExecutionManagerImpl$doStartRunProfile$startRunnable$1.run(ExecutionManagerImpl.kt:234)
	at com.intellij.openapi.application.TransactionGuardImpl.runWithWritingAllowed(TransactionGuardImpl.java:209)
	at com.intellij.openapi.application.TransactionGuardImpl.access$100(TransactionGuardImpl.java:21)
	at com.intellij.openapi.application.TransactionGuardImpl$1.run(TransactionGuardImpl.java:191)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:881)
	at com.intellij.openapi.application.impl.ApplicationImpl$3.run(ApplicationImpl.java:513)
	at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:75)
	at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:118)
	at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:42)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:779)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:730)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:724)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:749)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:898)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:746)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$6(IdeEventQueue.java:439)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:791)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$7(IdeEventQueue.java:438)
	at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:105)
	at com.intellij.ide.IdeEventQueue.performActivity(IdeEventQueue.java:604)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:436)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:881)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:484)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)

I'm on MacOS 12.4, java 17.0.1 2021-10-19 LTS,
PyCharm 2022.2 ce
Build #PC-222.3345.131, built on July 27, 2022

Runtime version: 17.0.3+7-b469.32 aarch64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.

Is there anything I can do to fix this?

@tpasternak
Copy link
Collaborator

Hey @therearesomewhocallmetim, debugging works for me, despite the error you mentioned (I get it, too)

@tpasternak
Copy link
Collaborator

Closing, as this is likely to be fixed, please fill free to reopen if it still doesn't work for you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-maintainer Awaiting review from Bazel team on issues lang: python Python rules integration os: linux Linux support product: PyCharm PyCharm plugin topic: debugging Issues related to debugging type: bug
Projects
Development

No branches or pull requests

9 participants