You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trying to create an animation in Julia using notebooks on VS Code, causes high CPU and RAM usage. This bug takes place when restarting and re-running a cell which creates said notebook.
Reproducing the bug
I have found a way to reproduce this bug, at least on my machine, where the steps are:
Create a new Jupyter notebook file and open it in a new VS Code session;
Write the following piece of code in a single cell;
using Plots
anim =@animatefor i=1:10plot()
for n=0:2plot!(rand(3), rand(3), label="n = $n")
endendmp4(anim)
Run the cell, wait for it to finish, restart the kernel and run the cell again;
Save and close the notebook when it finishes running;
There should be now a stray Julia process in running in the background at 100% CPU usage on a single core, as well as two temporary directory managed by Julia, in /tmp/jl_*, that weren’t cleaned up. Closing VS Code will not free any resources.
Fortunately, I have found a workaround.
If instead of the previous block of code, you explicitly display the video and cleanup all files and variables, with, e.g.
using Plots
anim =@animatefor i=1:10plot()
for n=0:2plot!(rand(3), rand(3), label="n = $n")
endend# store the video in a temporary directory and embed it in this notebook
tempdir =mktempdir()
video =mp4(anim, "$tempdir/output.mp4", fps=32)
display(video)
# remove the video and the animation object because the video is now embedded in this notebookrm(anim.dir, recursive=true)
rm(tempdir, recursive=true)
anim =nothing
GC.gc()
then you are able of running and re-running the notebook without leaving stray Julia processes.
However, sometimes, there are still leftover directories that aren't cleaned up. I think this takes place whenever an animation fails at some point and my cleanup code doesn't run.
Now that I am here, does anybody happens to know an easier and boiler-plate free way of embedding the video directly into your Jupyter notebook on VS Code?
I rarely ever want to save the video to disk, because this way the notebook can be completely self-contained and easily shared with others without having to worry about carrying additional files.
I think having this option by default, as it is the default when you output plots, for example, would be very convenient and better incorporate the philosophy of the notebook.
Backends
This bug occurs on
Backend
yes
no
untested
gr (default)
x
pythonplot
x
plotlyjs
x
pgfplotsx
x
unicodeplots
x
inspectdr
x
gaston
x
Versions
Plots.jl version: v1.38.17
Backend version: GR v0.72.9
Output of versioninfo():
Julia Version 1.9.3
Commit bed2cd540a1 (2023-08-24 14:43 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 4 × Intel(R) Core(TM) i5-7300HQ CPU @ 2.50GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-14.0.6 (ORCJIT, skylake)
Threads: 1 on 4 virtual cores
The text was updated successfully, but these errors were encountered:
I would like to note that although the output reports only one single thread being, as is the case in the notebook in VS Code, the mp4 function seems to somehow make use of all of my cores, at least temporarily.
I'm unsure if this is intended, or even relevant.
Part of what you may be seeing the result of encoding the video with FFMPEG under the hood. Encoding video is very resource intensive. The animation code also works by saving frames to disk and then compiling them into a video.
Details
Trying to create an animation in Julia using notebooks on VS Code, causes high CPU and RAM usage. This bug takes place when restarting and re-running a cell which creates said notebook.
Reproducing the bug
I have found a way to reproduce this bug, at least on my machine, where the steps are:
/tmp/jl_*
, that weren’t cleaned up. Closing VS Code will not free any resources.Fortunately, I have found a workaround.
If instead of the previous block of code, you explicitly display the video and cleanup all files and variables, with, e.g.
then you are able of running and re-running the notebook without leaving stray Julia processes.
However, sometimes, there are still leftover directories that aren't cleaned up. I think this takes place whenever an animation fails at some point and my cleanup code doesn't run.
Now that I am here, does anybody happens to know an easier and boiler-plate free way of embedding the video directly into your Jupyter notebook on VS Code?
I rarely ever want to save the video to disk, because this way the notebook can be completely self-contained and easily shared with others without having to worry about carrying additional files.
I think having this option by default, as it is the default when you output plots, for example, would be very convenient and better incorporate the philosophy of the notebook.
Backends
This bug occurs on
Versions
Plots.jl version: v1.38.17
Backend version: GR v0.72.9
Output of
versioninfo()
:The text was updated successfully, but these errors were encountered: