Skip to content

Commit 8ef5533

Browse files
Update Debugging01.md
1 parent d221f44 commit 8ef5533

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

docs/tutorials/Debugging01.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ from xlpython import *
3535

3636
# Add these two lines
3737
import ptvsd
38-
ptvsd.enable_attach(secret='cows')
38+
try:
39+
ptvsd.enable_attach(secret='cows')
40+
except ptvsd.AttachAlreadyEnabledError:
41+
pass
42+
3943

4044
@xlfunc
4145
def DoubleSum(x, y):
@@ -44,6 +48,8 @@ def DoubleSum(x, y):
4448

4549
These to lines enable us to attach the Visual Studio debugger to the Python script, so that we can debug it. Note that the Python process itself must be running for this to work, and ExcelPython does not launch it until it is needed - so just to make sure that it is running and that the `Book1.py` script is loaded, click 'Import Python UDFs'.
4650

51+
(Note: the `try ... except` clause is needed because if `enable_attach` is called twice PTVS will complain that it's already been called. Since we have no way of controlling if it's already been called (for example if the script is reloaded, or if it is called in a different script) we catch the error and ignore it, as recommended in the PTVS documentation.)
52+
4753
At this point you may need to unblock a port on the Windows firewall:
4854

4955
![image](https://cloud.githubusercontent.com/assets/5197585/4387988/f02fbbe8-43e4-11e4-997e-31f12adbdf98.png)

0 commit comments

Comments
 (0)