-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add subfunction for prep course #6
Comments
i'm trying to grade a notebook locally with this code, but im getting an error. from nbgrader import utils
def grade(nb):
total_score = 0
max_total_score = 0
for cell in nb.cells:
if utils.is_grade(cell):
score, max_score = utils.determine_grade(cell)
total_score += score
max_total_score += max_score
return total_score, max_total_score
from traitlets.config import Config
import nbconvert
#####
def execute(notebook, timeout=None, allow_errors=True):
c = Config()
c.NotebookExporter.preprocessors = [
"nbconvert.preprocessors.ClearOutputPreprocessor",
"nbconvert.preprocessors.ExecutePreprocessor",
]
c.ExecutePreprocessor.allow_errors = allow_errors
if timeout:
c.ExecutePreprocessor.timeout = timeout
exporter = nbconvert.NotebookExporter(config=c)
notebook, _ = exporter.from_notebook_node(notebook)
return nbformat.reads(notebook, as_version=nbformat.NO_CONVERT)
####
import nbformat
notebook_path = 'Exercise notebook.ipynb'
notebook = nbformat.read(notebook_path, as_version=nbformat.NO_CONVERT)
notebook = execute(notebook, timeout=60) # utils.execute(notebook, timeout)
total_score, max_score = grade(notebook) Traceback (most recent call last):
File "grade.py", line 40, in <module>
notebook = execute(notebook, timeout=60) # utils.execute(notebook, timeout)
File "grade.py", line 30, in execute
notebook, _ = exporter.from_notebook_node(notebook)
File "/home/mig/.virtualenvs/grading-notebooks-locally/lib/python3.7/site-packages/nbconvert/exporters/notebook.py", line 32, in from_notebook_node
nb_copy, resources = super(NotebookExporter, self).from_notebook_node(nb, resources, **kw)
File "/home/mig/.virtualenvs/grading-notebooks-locally/lib/python3.7/site-packages/nbconvert/exporters/exporter.py", line 139, in from_notebook_node
nb_copy, resources = self._preprocess(nb_copy, resources)
File "/home/mig/.virtualenvs/grading-notebooks-locally/lib/python3.7/site-packages/nbconvert/exporters/exporter.py", line 316, in _preprocess
nbc, resc = preprocessor(nbc, resc)
File "/home/mig/.virtualenvs/grading-notebooks-locally/lib/python3.7/site-packages/nbconvert/preprocessors/base.py", line 47, in __call__
return self.preprocess(nb, resources)
File "/home/mig/.virtualenvs/grading-notebooks-locally/lib/python3.7/site-packages/nbconvert/preprocessors/execute.py", line 405, in preprocess
nb, resources = super(ExecutePreprocessor, self).preprocess(nb, resources)
File "/home/mig/.virtualenvs/grading-notebooks-locally/lib/python3.7/site-packages/nbconvert/preprocessors/base.py", line 69, in preprocess
nb.cells[index], resources = self.preprocess_cell(cell, resources, index)
File "/home/mig/.virtualenvs/grading-notebooks-locally/lib/python3.7/site-packages/nbconvert/preprocessors/execute.py", line 438, in preprocess_cell
reply, outputs = self.run_cell(cell, cell_index, store_history)
File "/home/mig/.virtualenvs/grading-notebooks-locally/lib/python3.7/site-packages/nbconvert/preprocessors/execute.py", line 578, in run_cell
exec_reply = self._poll_for_reply(parent_msg_id, cell, timeout)
File "/home/mig/.virtualenvs/grading-notebooks-locally/lib/python3.7/site-packages/nbconvert/preprocessors/execute.py", line 479, in _poll_for_reply
if msg['parent_header'].get('msg_id') == msg_id:
TypeError: 'coroutine' object is not subscriptable
sys:1: RuntimeWarning: coroutine 'ZMQSocketChannel.get_msg' was never awaited |
This is due to problems with lib versions, jupyter-client I think. |
managed to fix it with |
found the answer here jupyter/jupyter_client#637 |
🕵🏻 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TBD
Containing only the necessary functions to grade the notebook and return a grade.
The text was updated successfully, but these errors were encountered: