There are cases where code needs to act differently if running in Visual Studio Code.
Does anybody know the most efficient way to detect that the python code is running in the Visual Studio Code debugger?
So far, the best way I could find was using:
import sys
if 'debugpy' in sys.modules:
print("Running in VS Code")
On vscode the environment variable TERM_PROGRAM is set to 'vscode', you can check it by:
import os
if 'TERM_PROGRAM' in os.environ.keys() and os.environ['TERM_PROGRAM'] == 'vscode':
print("Running in VS Code")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With