DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Python Debug pulling in cached code

When using VS code to debug a DIAdem python script I am seeing a stale version of source being passed to the MS Code debugger so that the debugger view is not in sync with the code execution.   Looks like the code that is executing is the newer edited source file but does not align with the source debugger.

 

Initially I suspected that VS Code is caching the file...   So I cleaned all I could find and cleared the editor history.   Removed all the appdata info and still old file is being pulled up.  The debug file that is opened is at the same path as the source but they do not match.   I also removed the python cache folder.  But still there is a sync problem.  

 

Closed and opened DIAdem app.  This did fix the issue but is a little expensive to do and only syncs once after app restart.  Since it is a remote debug connection how can I force the connection to reload the source files without restarting?

 

I am using the debug launcher:

# --------------------------------------------------------------------
# -- Python Script File
# -- Created on 10/26/2020 10:09:44
# -- Author: username
# -- Comment: .
# --------------------------------------------------------------------
from DIAdem import Application as dd

if False:
    import DIAdem_CodeCompletion as dd

# --------------------------------------------------------------------
# -- Beginning of user code --

import your_file_module
import importlib
importlib.reload(your_file_module)

 

Perhaps there is a required unload / reset that is needed?

0 Kudos
Message 1 of 3
(1,663 Views)

If I rename the source file to a new name and have the launcher point to it then the current source file is loaded.  So this is faster than relaunching and gives a clue where the caching is.

0 Kudos
Message 2 of 3
(1,648 Views)

Hi az_ltr,

I could also see the behavior of VSCode to display old files.
I have found two workarounds:
1. Before debugging the changed files again, I close all source files in VSCode. The modified file is then automatically reloaded when the breakpoint is reached.
2. I use a launch.json configuration with the correct path to my Python source files.

"remoteRoot": "C:/temp/myscripts"

 Of course, the current file must always be loaded in DIAdem with importlib.reload().

 

I hope this works for you too,

DIAdemo

Message 3 of 3
(1,521 Views)