##// END OF EJS Templates
Swallow potential exceptions from showtraceback() (#13934)...
Swallow potential exceptions from showtraceback() (#13934) The nbgrader project is aware of a form of cheating where students disrupt `InteractiveShell.showtraceback` in hopes of hiding exceptions to avoid losing points. They have implemented a solution to prevent this cheating from working on the client side, and have some tests to demonstrate this technique: https://github.com/jupyter/nbgrader/blob/main/nbgrader/tests/apps/files/submitted-cheat-attempt.ipynb https://github.com/jupyter/nbgrader/blob/main/nbgrader/tests/apps/files/submitted-cheat-attempt-alternative.ipynb In essence, these attacks import the interactive shell and erase the traceback handler so that their failing tests won't report failures. ```python import IPython.core.interactiveshell IPython.core.interactiveshell.InteractiveShell.showtraceback = None ``` The problem is that this causes an exception inside the kernel, leading to a stalled execution. The kernel has stopped working, but the client continues to wait for messages. So far, nbgrader's solution to this is to require a timeout value so the client can eventually decide it is done. This prevents allowing a value of `None` for `Execute.timeout` because this would cause a test case to infinitely hang. This commit addresses the problem by making `InteractiveShell._run_cell` a little more protective around it's call to `showtraceback()`. There is already a try/except block around running the cell. This commit adds a finally clause so that the method will _always_ return an `ExecutionResult`, even if a new exception is thrown within the except clause. For the record, the exception thrown is: TypeError: 'NoneType' object is not callable Accepting this change will allow nbgrader to update `nbgrader.preprocessors.Execute` to support a type of `Integer(allow_none=True)` as the parent `NotebookClient` intended. Discussion about this is ongoing in jupyter/nbgrader#1690.

File last commit:

r27139:919f313f
r28101:e548ee23 merge
Show More
autogen_api.py
80 lines | 2.9 KiB | text/x-python | PythonLexer
#!/usr/bin/env python
"""Script to auto-generate our API docs.
"""
import os
import sys
pjoin = os.path.join
here = os.path.abspath(os.path.dirname(__file__))
sys.path.append(pjoin(os.path.abspath(here), 'sphinxext'))
from apigen import ApiDocWriter
source = pjoin(here, 'source')
#*****************************************************************************
if __name__ == '__main__':
package = 'IPython'
outdir = pjoin(source, 'api', 'generated')
docwriter = ApiDocWriter(package,rst_extension='.rst')
# You have to escape the . here because . is a special char for regexps.
# You must do make clean if you change this!
docwriter.package_skip_patterns += [r'\.external$',
# Extensions are documented elsewhere.
r'\.extensions',
# Magics are documented separately
r'\.core\.magics',
# This isn't API
r'\.sphinxext',
# Shims
r'\.kernel',
r'\.terminal\.pt_inputhooks',
]
# The inputhook* modules often cause problems on import, such as trying to
# load incompatible Qt bindings. It's easiest to leave them all out. The
docwriter.module_skip_patterns += [
r"\.lib\.inputhook.+",
r"\.ipdoctest",
r"\.testing\.plugin",
# Backwards compat import for lib.lexers
r"\.nbconvert\.utils\.lexers",
# We document this manually.
r"\.utils\.py3compat",
# These are exposed in display
r"\.core\.display",
r"\.lib\.display",
# Shims
r"\.config",
r"\.consoleapp",
r"\.frontend$",
r"\.html",
r"\.nbconvert",
r"\.nbformat",
r"\.parallel",
r"\.qt",
# this is deprecated.
r"\.utils\.version",
# Private APIs (there should be a lot more here)
r"\.terminal\.ptutils",
]
# main API is in the inputhook module, which is documented.
# These modules import functions and classes from other places to expose
# them as part of the public API. They must have __all__ defined. The
# non-API modules they import from should be excluded by the skip patterns
# above.
docwriter.names_from__all__.update({
'IPython.display',
})
# Now, generate the outputs
docwriter.write_api_docs(outdir)
# Write index with .txt extension - we can include it, but Sphinx won't try
# to compile it
docwriter.write_index(outdir, 'gen.txt',
relative_to = pjoin(source, 'api')
)
print ('%d files written' % len(docwriter.written_modules))