Skip to content

Instantly share code, notes, and snippets.

@libbkmz
Created July 1, 2019 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save libbkmz/3d543b3be827d705d603cbead6d16333 to your computer and use it in GitHub Desktop.
Save libbkmz/3d543b3be827d705d603cbead6d16333 to your computer and use it in GitHub Desktop.
Use Visual Studio 2017 com api to attach to running python process with loaded dll for debugging
import os,sys
import win32com.client as win32
# import pythoncom as com
def attach_visual_studio():
# a = com.GetActiveObject("VisualStudio.DTE.12.0")
dte = win32.GetActiveObject("VisualStudio.DTE.15.0")
# https://docs.microsoft.com/en-us/dotnet/api/envdte80.dte2?view=visualstudiosdk-2017
# @TODO: check if there more than 1 solution open.
# Use corresponsing VS solution instance in that case
for x in dte.Debugger.LocalProcesses:
if x .ProcessID == os.getpid():
x.Attach()
break
if __name__ == "__main__":
attach_visual_studio()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment