Skip to content
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

Ctrl+C not working with ProgressLogging #3556

Open
KnutAM opened this issue Feb 27, 2024 · 5 comments
Open

Ctrl+C not working with ProgressLogging #3556

KnutAM opened this issue Feb 27, 2024 · 5 comments

Comments

@KnutAM
Copy link

KnutAM commented Feb 27, 2024

When running (via include("my_file.jl")) the MWE below, interrupting with Ctrl+C doesn't work unless taking the sleeping branch: It keeps running until the iterations complete.

While I guess this is related to long-standing issues in Julia (e.g. JuliaLang/julia#35524), it works when using TerminalLoggers.jl (and running outside VSCode).

So I'm just putting it here in case someone would have an idea how to fix the behavior.

using ProgressLogging

function expensive_calc()
    x = 0.0
    for _ in 1:10000
        x += sum(x -> sin(x - 0.5), rand(1000))
    end
    return x
end

function run(;steps=100, do_sleep=false)
    x = 0.0
    @progress for i in 1:steps
        if do_sleep
            sleep(0.04)
        else
            x += expensive_calc()
        end
    end
    return x
end

run(;do_sleep=true) # Ctrl+C works
run() # Ctrl+C doesn't work
versioninfo

Running VSCode plugin v1.73.2

Julia Version 1.10.1
Commit 7790d6f064 (2024-02-13 20:41 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 8 × 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, tigerlake)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)
Environment:
  JULIA_PKG_OFFLINE = false
  JULIA_PKG_USE_CLI_GIT = true
  JULIA_EDITOR = code.cmd
  JULIA_NUM_THREADS =
@pfitzseb
Copy link
Member

pfitzseb commented Mar 4, 2024

If you hit Ctrl-C three times within a second, we'll send out an interrupt signal, which doesn't require your inner loop to yield, but may be unsafe (i.e. it may interrupt not your code, but something internal to the extension).

It's probably worth adding a setting for always sending the signal on supported platforms though.

@KnutAM
Copy link
Author

KnutAM commented Mar 4, 2024

Thanks for the tip! Unfortunately, for me this doesn't interrupt the process.
Making sure expensive_calc takes more than a second didn't make a difference either.

@pfitzseb
Copy link
Member

pfitzseb commented Mar 4, 2024

Peek.2024-03-04.16-06.webm

That works semi-reliably for me.

What OS are you on?

@KnutAM
Copy link
Author

KnutAM commented Mar 4, 2024

Windows 10, now I also tried running via Ctrl+Enter as you do in the video, but still it doesn't interrupt. Even when holding in Ctrl+C for 10s of seconds (or pressing 20x times) (after increasing the runtime). I've tried it on two computers running basically same setup though (Win 10, Julia 1.10.1/1.10.2, extension v1.73.2, vscode 1.87.

vs code about
Version: 1.87.0 (user setup)
Commit: 019f4d1419fbc8219a181fab7892ebccf7ee29a2
Date: 2024-02-27T23:41:44.469Z
Electron: 27.3.2
ElectronBuildId: 26836302
Chromium: 118.0.5993.159
Node.js: 18.17.1
V8: 11.8.172.18-electron.0
OS: Windows_NT x64 10.0.19045

@pfitzseb
Copy link
Member

pfitzseb commented Mar 5, 2024

Ah, yeah, that explains it. We can't really do better than that on Windows, unfortunately, except for majorly reworking how code is evaluated in VS Code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants