Skip to content

VS Code pre-release does not reload code on restart of the debugger #157655

Closed

Description

Discussed in microsoft/vscode-python#19600

Originally posted by Emergency5779 August 1, 2022
All of a sudden VS Code (preview) does not load changes made to the code, when restarting the debugger.

I have spent hours googling, but I have come up empty-handed. Can anyone enlighten me on what is going on. Is there a new config option to set whether the code is to be reloaded when restarting the debugger?

If I stop the execution of the script, and run the debugger again, the latest code changes are loaded.

Activity

  1. karthiknadig commented on Aug 3, 2022

    @karthiknadig
    Member

    Pavel Minaev (@int19h) Has something changed in the DAP client in how restart is handled?

    /cc Rich Chiodo (@rchiodo)

  2. int19h commented on Aug 3, 2022

    @int19h

    If I understand correctly, this isn't about restarting the session at all - this is about edit-and-continue (pause, edit code, resume).

    I can't think of any recent changes in pydevd that would break this, but Fabio Zadrozny (@fabioz) would know more.

  3. Emergency5779 commented on Aug 4, 2022

    @Emergency5779

    Edit and continue hasn't reloaded the code for python.

    I run the debugger. Before the debugger exits the session; I edit the code, save the code, and restart the debugger using the restart button. The debugger then exits and debugs the code which was originally debugged, instead of debugging the updated code.

    If I stop the stop the session using the stop button and then debug the code again, the updated code is debugged.

    Expected behaviour for the restart button; is to stop the debugger, and run the debugger again based on the updated code.

    Switching to the release version of VS Code, the code is reloaded as expected on restart, even without saving it first, which is practical.

  4. Emergency5779 commented on Aug 4, 2022

    @Emergency5779

    Having downgraded and upgraded the following extensions; intellicode, python and pylance, I can't reproduce the debugger not loading the saved code on restart.

    However, the stable version of VS code, saves the code before reloading it, which is practical, while the pre-release version doesn't. At least after downgrading and upgrading the extensions, the debugger does pick up the saved version.

  5. fabioz commented on Aug 4, 2022

    @fabioz
    Contributor

    I couldn't reproduce it in a simple test (when autoReload is properly set in the launch it does reload properly for me provided that autoReload is set in the launch config).

    Pavel Minaev (@int19h) Karthik Nadig (@karthiknadig) is it possible that autoReload is no longer set in one of the shortcuts being used in VSCode and this is what the user is seeing?

    Note that debugpy will do everything on the backend in this case, so, it creates a watcher for filesystem changes and doesn't rely on any connection or messages from the UI (this was always this way, so, it can only see changes it detects in the filesystem).

    Emergency5779 can you provide the logs when that happens?

    i.e.:

    • Run the command Extensions: Open Extensions Folder
    • Locate the Python extension directory, typically of the form ms-python.python-2022.*.****
    • In that directory ensure you do not have any debug*.log files, if you do, please delete them
    • Go back into VS Code and modify your launch.json to add the setting "logToFile": true, see below:
    {
        "name": "Python: Current File (Integrated Terminal)",
        "type": "python",
        "request": "launch",
        "program": "${file}",
        "console": "integratedTerminal",
        "autoReload": {"enable": true},
        "logToFile": true
    }
    
    • Start debugging
    • When done, go back into the extension directory and upload the debug*.log files into this GitHub issue.
  6. Emergency5779 commented on Aug 5, 2022

    @Emergency5779

    Thanks Fabioz,

    I came across the autoReload flag, but read it, as if it was designed for loading code on the fly with jit compilers, I didn't consider, that would also solve this problem, which is of course, is kind of obvious.

    While I have been using VS Code, the flag has never been needed with the release version, and up until recently it wasn't needed with the preview version either.

    With the flag set the preview version reloads the code, also without saving it first.

    When the change makes it into the release it would make sense to have a disclaimer about autoReload on restart, no longer being the default behaviour.

    How do I set this as default in the settings.json?

    Thanks a lot for your help, it was driving me crazy!

  7. Emergency5779 commented on Aug 5, 2022

    @Emergency5779

    At first setting the autoReload flag worked flawlessly without saving, but it stopped working again, it still reloads if I save the file first, but it also did that yesterday, after I downgraded and upgraded the python related extensions.

    debugpy.pydevd.20184.log
    debugpy.server-20184.log
    debugpy.adapter-336.log
    debugpy.launcher-38988.log
    debugpy.pydevd.44628.log
    debugpy.server-44628.log
    debugpy.adapter-40812.log
    debugpy.launcher-27856.log
    debugger.vscode_fafc7763-65fb-44cb-b077-34366269d4da.log
    debugpy.adapter-8032.log
    debugpy.launcher-16404.log

  8. fabioz commented on Aug 5, 2022

    @fabioz
    Contributor

    I'm not sure I follow: At first setting the autoReload flag worked flawlessly without saving.

    Auto-reload on the debugger can only work when the file is saved (since it works by checking for changes in the filesystem), so, I'm not sure if I follow what you mean that it worked without saving... can you elaborate a bit?

    -- if it did work without you saving that'd mean that some extension was auto-saving the contents...

  9. Emergency5779 commented on Aug 8, 2022

    @Emergency5779

    I have the same setup, and settings.json, in the release version and the pre-release version, though the one saves, while the other one doesn't. I have autosave onFocusChange flag set, perhaps the release version changes focus to run the debugger, and the pre-release version doesn't?

  10. fabioz commented on Aug 9, 2022

    @fabioz
    Contributor

    I have the same setup, and settings.json, in the release version and the pre-release version, though the one saves, while the other one doesn't. I have autosave onFocusChange flag set, perhaps the release version changes focus to run the debugger, and the pre-release version doesn't?

    Probably... either way, saving (or auto-saving) per se is not in the scope for the debugger (as it'll only track the contents of the filesystem), and I think it's not handled by vscode-python either.

    Brett Cannon (@brettcannon) Karthik Nadig (@karthiknadig) should this be closed/moved to vscode to know if something changed there?

  11. Emergency5779 commented on Aug 9, 2022

    @Emergency5779

    The config has a setting for saving before debug, but the pre-release version doesn't do it.

    image

  12. 23 remaining items

  13. rtetsoacrsf commented on Aug 13, 2022

    @rtetsoacrsf

    Work around
    Install multi-command extension
    Then replace the hotkey for Debug: Restart in keybindings.json:

        {
            "key": "ctrl+shift+f5",
            "command": "extension.multiCommand.execute",
            "args": 
            {
                "command": "multiCommand.restartDebug",
                "interval": 30,
                "sequence": [
                    "saveAll",
                    "workbench.action.debug.restart",
                ]
            }
        }
    
  14. added a commit that references this issue on Aug 15, 2022
    c5662ad
  15. added a commit that references this issue on Aug 15, 2022
    5864b1f
  16. added
    insiders-releasedPatch has been released in VS Code Insiders
    and removed
    unreleasedPatch has not yet been released in VS Code Insiders
    on Aug 16, 2022
  17. andreamah commented on Aug 16, 2022

    @andreamah
    Contributor

    Andre Weinand (@weinand) could you verify that this is fixed in insiders?

  18. weinand commented on Aug 16, 2022

    @weinand
    Contributor

    Andrea Mah (@andreamah) the fix works great, thanks a lot!

  19. added a commit that references this issue on Aug 18, 2022
    e4503b3
  20. alon1samuel commented on Aug 22, 2022

    @alon1samuel

    Thanks! Works for me as well

  21. locked and limited conversation to collaborators on Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugIssue identified by VS Code Team member as probable bugcandidateIssue identified as probable candidate for fixing in the next releasedebugDebug viewlet, configurations, breakpoints, adapter issuesinsiders-releasedPatch has been released in VS Code InsidersregressionSomething that used to work is now brokenverifiedVerification succeeded

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions