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

(Global) variables hidden/disappear when waiting for user input #1673

Closed
keunes opened this issue Aug 17, 2024 · 3 comments
Closed

(Global) variables hidden/disappear when waiting for user input #1673

keunes opened this issue Aug 17, 2024 · 3 comments
Assignees
Labels
needs repro Issue has not been reproduced yet

Comments

@keunes
Copy link

keunes commented Aug 17, 2024

Hello,
Not sure if this is expected or not, but while waiting for user input with the following code, all (global & local) variables disappear:

    print("Please enter the Deskpro ID of the article that you want to translate:")
    while True:
        try:
            if msvcrt.kbhit():  # Check if a key has been pressed
                article_id = input()
                article_processor.process_article(article_id, language_map)
            time.sleep(0.1)  # Sleep for a short period to prevent high CPU usage
        except KeyboardInterrupt:
            graceful_exit(signal.SIGINT, None)

This is a bit annoying because I have a background process running that I'd like to debug, for which I now cannot see the variables throughout the code. Before this point, switching threads reveals the different variables, but after this point none of the threads reveal any variables.

Before waiting for input:
image

While waiting for input:
image

@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python-debugger Sep 18, 2024
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Sep 18, 2024
@rchiodo
Copy link
Contributor

rchiodo commented Sep 18, 2024

This is by design. You can't evaluate anything while all the threads are in the running state.

@rchiodo rchiodo closed this as completed Sep 18, 2024
@keunes
Copy link
Author

keunes commented Oct 3, 2024

Hi @rchiodo
Thanks for your reply.

You can't evaluate anything while all the threads are in the running state

I must say I'm a bit confused (possibly because I'm not a developer). Why wouldn't you? Are variable values not reliable when all threads are running?

Given my scenario (one open thread listening for file changes, one for use input, and a main one), isn't it valid to just see the values of my variables, and see them changing as changes happen (as I've seen in other occasions)?

@rchiodo
Copy link
Contributor

rchiodo commented Oct 3, 2024

Are variable values not reliable when all threads are running?

No because they are changing continuously. And they are continuously going out of scope and into scope. There's no good way for the debugger to continuously read them. That's why debuggers only report values when all threads are stopped.

There are some tricks you can use though. Like 'log points'. They break in the debugger without you seeing anything and log a value. It slows the process down (well because all threads stop), but only long enough to send a message to VS code with the log output and then it continues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs repro Issue has not been reproduced yet
Projects
None yet
Development

No branches or pull requests

5 participants