marimo
marimo copied to clipboard
Too many open files when repeatedly regenerating plots
Describe the bug
I am using the mo.mpl.interactive(_ax) to display a single Matplotlib plot in a Marimo notebook. After repeatedly tweaking a single input number causing marimo to regenerate the plot, I received an OSError about too many open files. I simplified this this down to the included example: display a mo.mpl.interactive(_ax) figure and keep getting marimo to regenerate the figure until this occurs (ulimit -n is 256 on my system).
Traceback (most recent call last):
File "/opt/homebrew/Caskroom/miniconda/base/envs/py310/lib/python3.10/multiprocessing/process.py", line 314, in _bootstrap
self.run()
File "/opt/homebrew/Caskroom/miniconda/base/envs/py310/lib/python3.10/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "/opt/homebrew/Caskroom/miniconda/base/envs/py310/lib/python3.10/site-packages/marimo/_runtime/runtime.py", line 1151, in launch_kernel
kernel.run(request.execution_requests)
File "/opt/homebrew/Caskroom/miniconda/base/envs/py310/lib/python3.10/site-packages/marimo/_runtime/runtime.py", line 812, in run
self._run_cells(
File "/opt/homebrew/Caskroom/miniconda/base/envs/py310/lib/python3.10/site-packages/marimo/_runtime/runtime.py", line 588, in _run_cells
while cells_with_stale_state := self._run_cells_internal(cell_ids):
File "/opt/homebrew/Caskroom/miniconda/base/envs/py310/lib/python3.10/site-packages/marimo/_runtime/runtime.py", line 639, in _run_cells_internal
with self._install_execution_context(cell_id) as exc_ctx:
File "/opt/homebrew/Caskroom/miniconda/base/envs/py310/lib/python3.10/contextlib.py", line 135, in __enter__
return next(self.gen)
File "/opt/homebrew/Caskroom/miniconda/base/envs/py310/lib/python3.10/site-packages/marimo/_runtime/runtime.py", line 227, in _install_execution_context
with get_context().provide_ui_ids(str(cell_id)), redirect_streams(
File "/opt/homebrew/Caskroom/miniconda/base/envs/py310/lib/python3.10/contextlib.py", line 135, in __enter__
return next(self.gen)
File "/opt/homebrew/Caskroom/miniconda/base/envs/py310/lib/python3.10/site-packages/marimo/_runtime/redirect_streams.py", line 65, in redirect_streams
stderr_duped, stderr_read_fd, stderr_fd = dup2newfd(sys.stderr.fileno())
File "/opt/homebrew/Caskroom/miniconda/base/envs/py310/lib/python3.10/site-packages/marimo/_runtime/redirect_streams.py", line 37, in dup2newfd
read_fd, write_fd = os.pipe()
OSError: [Errno 24] Too many open files
Environment
"marimo": "0.1.79",
"OS": "Darwin",
"OS Version": "23.2.0",
"Processor": "arm",
"Python Version": "3.10.11",
"Binaries": {
"Chrome": "121.0.6167.85",
"Node": "v21.1.0"
},
"Requirements": {
"black": "23.3.0",
"click": "8.1.3",
"jedi": "0.18.2",
"pymdown-extensions": "10.0.1",
"tomlkit": "0.12.3",
"tornado": "6.3.2",
"typing_extensions": "4.6.3"
}
}
Code to reproduce
# local figure and axis
_fig, _ax = plt.subplots()
_ax.plot([1]) # keep changing what you are plotting just to get the plot to regenerate
mo.mpl.interactive(_ax)
Since 0.1.81, we’ve refactored this code quite a bit to be more performant (and opening only 1 server). Do you mind trying that out and reporting back?
closing as this should be fixed now, please re-open otherwise