-
Notifications
You must be signed in to change notification settings - Fork 293
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
Monkey patch the kernel to allow debugging and tracebacks to coexist #8671
Conversation
@DonJayamanne it would be great if you could look at this one when you get back. I'm a little nervous patching the kernel. Thought there might be some other way to patch it. |
This also fixes errors with stepping into previously defined cells. They had the same problem as the stack trace. |
# Variable that prevent wrapping from happing more than_once | ||
__VSCODE_wrapped_run_cell = False | ||
|
||
# This function computes the hash for the code. It must follow the same algorithm as in use here: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like that logic should be in a shared location
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha nevermind, python vs ts
src/test/datascience/helpers.ts
Outdated
return codeCell && (numberOfCells === -1 || numberOfCells === codeCells!.length) ? true : false; | ||
}, | ||
defaultNotebookTestTimeout, | ||
`No code cell found in interactive window notebook documen` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: document,
also - is there a reason you want to use backticks for a constant string here?
@@ -593,4 +595,97 @@ def foo(): | |||
`Cursor did not move to expected line when hitting stepping into` | |||
); | |||
}); | |||
|
|||
test('Step into a previous cell', async () => { | |||
// Need a function and a call to i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: another missing t!
Codecov Report
@@ Coverage Diff @@
## main #8671 +/- ##
=====================================
- Coverage 71% 71% -1%
=====================================
Files 384 384
Lines 24624 24633 +9
Branches 3789 3790 +1
=====================================
- Hits 17609 17545 -64
- Misses 5480 5563 +83
+ Partials 1535 1525 -10
|
Fixes #8568
The root cause was explained in #8568 but I'll reiterate here.
We have code that does this:
This environment variable is used by the kernel to 'name' a cell execution so that when we get a stackframe in the debugger, it can be uniquely identified.
The problem was it was never being 'unset'.
So when an error occurs and jupyter tries to parse all of the cells that lead to an exception, it can't determine which cell
<ipython-2-hashyvalue>
is actually referring to.Example:
def foo():\n raise Exception("FOO")\n
import os;os.environ["IPYKERNEL_CELL_NAME"] = '<ipython-1-hashy.py>'
as a silent celldef foo():\n raise Exception("FOO")\n
def foo():\n raise Exception("FOO")\n
with<ipython-1-hashy.py>
foo()
import os;os.environ["IPYKERNEL_CELL_NAME"] = '<ipython-2-hashy2.py>'
as a silent cellimport os;os.environ["IPYKERNEL_CELL_NAME"] = '<ipython-2-hashy2.py>'
with<ipython-1-hashy.py>
because IPYKERNEL_CELL_NAME was setfoo()
foo()
with<ipython-2-hashy2.py>
<ipython-1-hashy.py>
is mapped to theimport os;os.environ["IPYKERNEL_CELL_NAME"] = '<ipython-2-hashy2.py>
from step 7 instead ofdef foo():\n raise Exception("FOO")\n
from step 3The crux of the problem is that we need an environment variable set during a cell executing but then unset for everything that comes after it (or set to something different).
What if we could execute the code we use to generate the hash inside the kernel somehow?
I had 3 ideas on how to solve this (picked the last one)
I picked the last one because:
pre_run_code_hook
is deprecated and doesn't seem to actually get the code. The code is necessary in order to compute the hash. Plus we'd have to write an entire kernel extension.