1+ # ############################################################################
2+ #
3+ # Copyright (c) Microsoft Corporation.
4+ #
5+ # This source code is subject to terms and conditions of the Apache License, Version 2.0. A
6+ # copy of the license can be found in the License.html file at the root of this distribution. If
7+ # you cannot locate the Apache License, Version 2.0, please send an email to
8+ # vspython@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
9+ # by the terms of the Apache License, Version 2.0.
10+ #
11+ # You must not remove this notice, or any other, from this software.
12+ #
13+ # ###########################################################################
14+
115import datetime
216import os
317import sys
@@ -27,6 +41,19 @@ def log(txt):
2741 finally :
2842 f .close ()
2943
44+ ptvsd_secret = os .getenv ('WSGI_PTVSD_SECRET' )
45+ if ptvsd_secret :
46+ log ('Enabling ptvsd ...\n ' )
47+ try :
48+ import ptvsd
49+ try :
50+ ptvsd .enable_attach (ptvsd_secret )
51+ log ('ptvsd enabled.\n ' )
52+ except :
53+ log ('ptvsd.enable_attach failed\n ' )
54+ except ImportError :
55+ log ('error importing ptvsd.\n ' )
56+
3057def get_wsgi_handler (handler_name ):
3158 if not handler_name :
3259 raise Exception ('WSGI_ALT_VIRTUALENV_HANDLER env var must be set' )
@@ -92,4 +119,4 @@ def get_venv_handler():
92119 log ('Getting handler %s\n ' % os .getenv ('WSGI_ALT_VIRTUALENV_HANDLER' ))
93120 handler = get_wsgi_handler (os .getenv ('WSGI_ALT_VIRTUALENV_HANDLER' ))
94121 log ('Got handler: %r\n ' % handler )
95- return handler
122+ return handler
0 commit comments