-
Notifications
You must be signed in to change notification settings - Fork 389
Description
Bug description
When trying to render a quarto notebook with Python code from the command line I'm seeing behavior consistent with a persistent jupyter kernel. I would expect that each call to quarto render would run in a new, clean kernel.
For example consider the file test.qmd with the text
---
title: "Test"
author: "Test"
jupyter: python3
---
Test test test.
```{python}
import multiprocessing
multiprocessing.set_start_method("fork")
```
If I run
quarto render test.qmd --to html
from the command line once then everything renders fine, but I do see some Python threads that persist even after the command line prompt has returned.
If I run the same command again then quarto fails with the error
Executing 'test.ipynb'
Cell 1/1...ERROR:
An error occurred while executing the following cell:
------------------
import multiprocessing
multiprocessing.set_start_method("fork")
------------------
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
Input In [3], in <cell line: 2>()
1 import multiprocessing
----> 2 multiprocessing.set_start_method("fork")
File /usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/context.py:243, in DefaultContext.set_start_method(self, method, force)
241 def set_start_method(self, method, force=False):
242 if self._actual_context is not None and not force:
--> 243 raise RuntimeError('context has already been set')
244 if method is None and force:
245 self._actual_context = None
RuntimeError: context has already been set
RuntimeError: context has already been set
Force quitting those dangling Python threads does allow me to render again without problem.
If I include a cell like
```{python}
print(locals())
a = 2
print(locals())
```
then I also see the locals() dictionary growing from call to call, even holding variables from previous renders that are no longer in the notebook, consistent with the kernel persisting from call to call.
Operating System: MacOS 10.15.7 (19H2026)
Python Version: Python 3.9.6 (default, Jun 29 2021, 06:20:32) [Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Quarto Version: 1.1.251
Any help would be appreciated, and apologies if I'm missing something obvious. Many thanks for a great project.
Checklist
- Please include a minimal, fully reproducible example in a single .qmd file? Please provide the whole file rather than the snippet you believe is causing the issue.
- Please format your issue so it is easier for us to read the bug report.
- Please document the RStudio IDE version you're running (if applicable), by providing the value displayed in the "About RStudio" main menu dialog?
- Please document the operating system you're running. If on Linux, please provide the specific distribution.