Julia gets stuck reading CSV when followed by threaded loop

I am seeing the following strange behavior where Julia seems to get stuck and becomes unresponsive.

Generate some data and save as .csv:

using CSV, DataFrames
d = DataFrame(rand(10000,10), :auto)
CSV.write("test.csv", d)

Now when I execute the following code Julia gets stuck after 3-4 times on my machine. This seems to be related to the threaded loop - when I remove the threads macro the code executes fine many times.

df = CSV.read("test.csv", DataFrame)

Threads.@threads for n in 1:300
end

Can anyone reproduce this? I am on Julia 1.10.4 and CSV v0.10.14

Assuming you meant

this runs fine for me.

julia> versioninfo()
Julia Version 1.10.4
Commit 6f77e2ad37 (2024-08-13 14:35 UTC)
Platform Info:
  OS: macOS (arm64-apple-darwin23.6.0)
  CPU: 16 × Apple M3 Max
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
Threads: 1 default, 0 interactive, 1 GC (on 12 virtual cores)

As weird as it may sound, the original version with the empty loop at the end was what I intended. If I execute that second cell multiple times, Julia usually gets stuck after 3-4 times. Would you mind giving that a try?

Are you using jupyter or Pluto.jl or something like that? Might be relevant

No, I’m running directly in VS Code.

Actually, when I put the same code into a script and execute it directly in the terminal it seems to work fine. So perhaps a VS Code issue?

Running in the terminal, I too am not seeing Julia get stuck despite multiple calls of the empty loop.

Maybe it’s just the visual in VSCode that gets stuck?

It’s certainly something within VS code but I don’t think it is just the visual. In a more complex example I am saving information to disk, and once VS code gets stuck the creating of files stops.

Your code snippet also runs fine for me, both in the REPL, and in VS Code.

versioninfo()
Julia Version 1.10.4
Commit 48d4fd4843 (2024-06-04 10:41 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 8 × Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, skylake)
Threads: 8 default, 0 interactive, 4 GC (on 8 virtual cores)
Environment:
  JULIA_NUM_THREADS = 8
  JULIA_EDITOR = code
VS Code v1.92.1

Version: 1.92.1 (user setup)
Commit: eaa41d57266683296de7d118f574d0c2652e1fc4
Date: 2024-08-07T20:16:39.455Z
Electron: 30.1.2
ElectronBuildId: 9870757
Chromium: 124.0.6367.243
Node.js: 20.14.0
V8: 12.4.254.20-electron.0
OS: Windows_NT x64 10.0.19045

VS Code Julia extension v1.105.2

Thanks for checking! Does it also work fine when executing multiple (>4) times in VS Code (e.g., pressing Alt+Enter multiple times with the second part of the code in a script)?

  • As a Julia script (.jl) it always executes fine, no matter how often I spam alt/ctrl + enter.
  • As a Jupyter notebook (.ipynb),
    • When repeatedly running the second cell (CSV.read, @threads) at a normal pace using ctrl+enter, ctrl+alt+enter, or the run icon, everything works fine.
    • When spamming ctrl(+alt)+enter, say 10 times per second during 10 seconds, everything is still fine.
    • When spamming the run icon, I can get VS Code stuck. I’m not entirely sure if I am in fact clicking run, or stop (which the run icon turns into when a cell is running), as the cell normally finishes execution basically immediately, but in any case the cell execution certainly does not stop. I can still run other cells (i.e. the first cell with the CSV.write), but to run the second cell again, I need to restart VS Code.