# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE in the project root
# for license information.

import sys


__author__ = "Microsoft Corporation <ptvshelp@microsoft.com>"
__version__ = "4.0.0a1"

DONT_DEBUG = []


def debug(filename, port_num, debug_id, debug_options, run_as):
    # TODO: docstring

    # import the wrapper first, so that it gets a chance
    # to detour pydevd socket functionality.
    import ptvsd.wrapper
    import pydevd

    args = [
            '--port', str(port_num),
            '--client', '127.0.0.1',
            ]
    if run_as == 'module':
        args.append('--module')
        args.extend(('--file', filename + ":"))
    else:
        args.extend(('--file', filename))
    sys.argv[1:0] = args
    try:
        pydevd.main()
    except SystemExit as ex:
        ptvsd.wrapper.ptvsd_sys_exit_code = ex.code
        raise

ptvsd/debugger.py
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE in the project root
# for license information.

import sys


__author__ = "Microsoft Corporation <ptvshelp@microsoft.com>"
__version__ = "4.0.0a1"

DONT_DEBUG = []


def debug(filename, port_num, debug_id, debug_options, run_as):
    # TODO: docstring

    # import the wrapper first, so that it gets a chance
    # to detour pydevd socket functionality.
    import ptvsd.wrapper
    import pydevd

    args = [
            '--port', str(port_num),
            '--client', '127.0.0.1',
            ]
    if run_as == 'module':
        args.append('--module')
        args.extend(('--file', filename + ":"))
    else:
        args.extend(('--file', filename))
    sys.argv[1:0] = args
    try:
        pydevd.main()
    except SystemExit as ex:
        ptvsd.wrapper.ptvsd_sys_exit_code = int(ex.code)
        raise

ptvsd/debugger.py
diff --git a/ptvsd/debugger.py b/ptvsd/debugger.py
index 42dbad3bc..399d711c4 100644
--- a/ptvsd/debugger.py
+++ b/ptvsd/debugger.py
@@ -32,5 +32,5 @@ def debug(filename, port_num, debug_id, debug_options, run_as):
     try:
         pydevd.main()
     except SystemExit as ex:
-        ptvsd.wrapper.ptvsd_sys_exit_code = ex.code
+        ptvsd.wrapper.ptvsd_sys_exit_code = int(ex.code)
         raise

Error reading integer
From VS (might not be a ptvsd bug, not sure at this point):
Create new python application
Add new item, python unit test
Set the unit test as startup file
F5

Result:
```
---------------------------
Microsoft Visual Studio
---------------------------
Error reading integer. Unexpected token: Boolean. Path 'exitCode'.
---------------------------
OK   
---------------------------
```
