We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Using sys.exit() with no arguments causes TypeError inside ptvsd
## Environment data

- PTVSD version: 4.1.3
- OS and version: Windows 10
- Python version (& distribution if applicable, e.g. Anaconda): 3.6
- Using VS Code or Visual Studio: VS

## Actual behavior

```
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "c:\program files (x86)\microsoft visual studio\2017\community\common7\ide\extensions\microsoft\python\core\ptvsd_launcher.py", line 119, in <module>
    
vspd.debug(filename, port_num, debug_id, debug_options, run_as)

  File "c:\program files (x86)\microsoft visual studio\2017\community\common7\ide\extensions\microsoft\python\core\Packages\ptvsd\debugger.py", line 37, in debug
    
run(address, filename, *args, **kwargs)

  File "c:\program files (x86)\microsoft visual studio\2017\community\common7\ide\extensions\microsoft\python\core\Packages\ptvsd\_local.py", line 48, in run_file
    
run(argv, addr, **kwargs)

  File "c:\program files (x86)\microsoft visual studio\2017\community\common7\ide\extensions\microsoft\python\core\Packages\ptvsd\_local.py", line 101, in _run
    
daemon.exitcode = int(ex.code)

TypeError
: 
int() argument must be a string, a bytes-like object or a number, not 'NoneType'
```


## Expected  behavior

No error

## Steps to reproduce:
1. Debug this code:

```
sys.exit()
```

https://docs.python.org/3/library/sys.html#sys.exit


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `ptvsd/_local.py`
Content:
```
1 # Copyright (c) Microsoft Corporation. All rights reserved.
2 # Licensed under the MIT License. See LICENSE in the project root
3 # for license information.
4 
5 import sys
6 import time
7 
8 import pydevd
9 from _pydevd_bundle.pydevd_comm import get_global_debugger
10 
11 from ptvsd.pydevd_hooks import install
12 from ptvsd.runner import run as no_debug_runner
13 from ptvsd.socket import Address
14 from ptvsd._util import new_hidden_thread
15 
16 
17 PYDEVD_DEFAULTS = {
18     '--qt-support=auto',
19 }
20 
21 
22 def _set_pydevd_defaults(pydevd_args):
23     args_to_append = []
24     for arg in PYDEVD_DEFAULTS:
25         if arg not in pydevd_args:
26             args_to_append.append(arg)
27     return pydevd_args + args_to_append
28 
29 
30 ########################
31 # high-level functions
32 
33 def debug_main(address, name, kind, *extra, **kwargs):
34     if not kwargs.pop('wait', False) and address.isserver:
35         def unblock_debugger():
36             debugger = get_global_debugger()
37             while debugger is None:
38                 time.sleep(0.1)
39                 debugger = get_global_debugger()
40             debugger.ready_to_run = True
41         new_hidden_thread('ptvsd.unblock_debugger', unblock_debugger).start()
42     if kind == 'module':
43         run_module(address, name, *extra, **kwargs)
44     else:
45         run_file(address, name, *extra, **kwargs)
46 
47 
48 def run_main(address, name, kind, *extra, **kwargs):
49     addr = Address.from_raw(address)
50     sys.argv[:] = _run_main_argv(name, extra)
51     runner = kwargs.pop('_runner', no_debug_runner)
52     runner(addr, name, kind == 'module', *extra, **kwargs)
53 
54 
55 ########################
56 # low-level functions
57 
58 def run_module(address, modname, *extra, **kwargs):
59     """Run pydevd for the given module."""
60     addr = Address.from_raw(address)
61     if not addr.isserver:
62         kwargs['singlesession'] = True
63     run = kwargs.pop('_run', _run)
64     prog = kwargs.pop('_prog', sys.argv[0])
65     filename = modname + ':'
66     argv = _run_argv(addr, filename, extra, _prog=prog)
67     argv.insert(argv.index('--file'), '--module')
68     run(argv, addr, **kwargs)
69 
70 
71 def run_file(address, filename, *extra, **kwargs):
72     """Run pydevd for the given Python file."""
73     addr = Address.from_raw(address)
74     if not addr.isserver:
75         kwargs['singlesession'] = True
76     run = kwargs.pop('_run', _run)
77     prog = kwargs.pop('_prog', sys.argv[0])
78     argv = _run_argv(addr, filename, extra, _prog=prog)
79     run(argv, addr, **kwargs)
80 
81 
82 def _run_argv(address, filename, extra, _prog=sys.argv[0]):
83     """Convert the given values to an argv that pydevd.main() supports."""
84     if '--' in extra:
85         pydevd = list(extra[:extra.index('--')])
86         extra = list(extra[len(pydevd) + 1:])
87     else:
88         pydevd = []
89         extra = list(extra)
90 
91     pydevd = _set_pydevd_defaults(pydevd)
92     host, port = address
93     argv = [
94         _prog,
95         '--port', str(port),
96     ]
97     if not address.isserver:
98         argv.extend([
99             '--client', host or 'localhost',
100         ])
101     return argv + pydevd + [
102         '--file', filename,
103     ] + extra
104 
105 
106 def _run_main_argv(filename, extra):
107     if '--' in extra:
108         pydevd = list(extra[:extra.index('--')])
109         extra = list(extra[len(pydevd) + 1:])
110     else:
111         extra = list(extra)
112     return [filename] + extra
113 
114 
115 def _run(argv, addr, _pydevd=pydevd, _install=install, **kwargs):
116     """Start pydevd with the given commandline args."""
117     #print(' '.join(argv))
118 
119     # Pydevd assumes that the "__main__" module is the "pydevd" module
120     # and does some tricky stuff under that assumption.  For example,
121     # when the debugger starts up it calls save_main_module()
122     # (in pydevd_bundle/pydevd_utils.py).  That function explicitly sets
123     # sys.modules["pydevd"] to sys.modules["__main__"] and then sets
124     # the __main__ module to a new one.  This makes some sense since
125     # it gives the debugged script a fresh __main__ module.
126     #
127     # This complicates things for us since we are running a different
128     # file (i.e. this one) as the __main__ module.  Consequently,
129     # sys.modules["pydevd"] gets set to ptvsd/__main__.py.  Subsequent
130     # imports of the "pydevd" module then return the wrong module.  We
131     # work around this by avoiding lazy imports of the "pydevd" module.
132     # We also replace the __main__ module with the "pydevd" module here.
133     if sys.modules['__main__'].__file__ != _pydevd.__file__:
134         sys.modules['__main___orig'] = sys.modules['__main__']
135         sys.modules['__main__'] = _pydevd
136 
137     daemon = _install(_pydevd, addr, **kwargs)
138     sys.argv[:] = argv
139     try:
140         _pydevd.main()
141     except SystemExit as ex:
142         daemon.exitcode = int(ex.code)
143         raise
144
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/ptvsd/_local.py b/ptvsd/_local.py
--- a/ptvsd/_local.py
+++ b/ptvsd/_local.py
@@ -139,5 +139,5 @@
     try:
         _pydevd.main()
     except SystemExit as ex:
-        daemon.exitcode = int(ex.code)
+        daemon.exitcode = 0 if ex.code is None else int(ex.code)
         raise

{"golden_diff": "diff --git a/ptvsd/_local.py b/ptvsd/_local.py\n--- a/ptvsd/_local.py\n+++ b/ptvsd/_local.py\n@@ -139,5 +139,5 @@\n     try:\n         _pydevd.main()\n     except SystemExit as ex:\n-        daemon.exitcode = int(ex.code)\n+        daemon.exitcode = 0 if ex.code is None else int(ex.code)\n         raise\n", "issue": "Using sys.exit() with no arguments causes TypeError inside ptvsd\n## Environment data\r\n\r\n- PTVSD version: 4.1.3\r\n- OS and version: Windows 10\r\n- Python version (& distribution if applicable, e.g. Anaconda): 3.6\r\n- Using VS Code or Visual Studio: VS\r\n\r\n## Actual behavior\r\n\r\n```\r\nDuring handling of the above exception, another exception occurred:\r\nTraceback (most recent call last):\r\n  File \"c:\\program files (x86)\\microsoft visual studio\\2017\\community\\common7\\ide\\extensions\\microsoft\\python\\core\\ptvsd_launcher.py\", line 119, in <module>\r\n    \r\nvspd.debug(filename, port_num, debug_id, debug_options, run_as)\r\n\r\n  File \"c:\\program files (x86)\\microsoft visual studio\\2017\\community\\common7\\ide\\extensions\\microsoft\\python\\core\\Packages\\ptvsd\\debugger.py\", line 37, in debug\r\n    \r\nrun(address, filename, *args, **kwargs)\r\n\r\n  File \"c:\\program files (x86)\\microsoft visual studio\\2017\\community\\common7\\ide\\extensions\\microsoft\\python\\core\\Packages\\ptvsd\\_local.py\", line 48, in run_file\r\n    \r\nrun(argv, addr, **kwargs)\r\n\r\n  File \"c:\\program files (x86)\\microsoft visual studio\\2017\\community\\common7\\ide\\extensions\\microsoft\\python\\core\\Packages\\ptvsd\\_local.py\", line 101, in _run\r\n    \r\ndaemon.exitcode = int(ex.code)\r\n\r\nTypeError\r\n: \r\nint() argument must be a string, a bytes-like object or a number, not 'NoneType'\r\n```\r\n\r\n\r\n## Expected  behavior\r\n\r\nNo error\r\n\r\n## Steps to reproduce:\r\n1. Debug this code:\r\n\r\n```\r\nsys.exit()\r\n```\r\n\r\nhttps://docs.python.org/3/library/sys.html#sys.exit\r\n\n", "before_files": [{"content": "# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License. See LICENSE in the project root\n# for license information.\n\nimport sys\nimport time\n\nimport pydevd\nfrom _pydevd_bundle.pydevd_comm import get_global_debugger\n\nfrom ptvsd.pydevd_hooks import install\nfrom ptvsd.runner import run as no_debug_runner\nfrom ptvsd.socket import Address\nfrom ptvsd._util import new_hidden_thread\n\n\nPYDEVD_DEFAULTS = {\n    '--qt-support=auto',\n}\n\n\ndef _set_pydevd_defaults(pydevd_args):\n    args_to_append = []\n    for arg in PYDEVD_DEFAULTS:\n        if arg not in pydevd_args:\n            args_to_append.append(arg)\n    return pydevd_args + args_to_append\n\n\n########################\n# high-level functions\n\ndef debug_main(address, name, kind, *extra, **kwargs):\n    if not kwargs.pop('wait', False) and address.isserver:\n        def unblock_debugger():\n            debugger = get_global_debugger()\n            while debugger is None:\n                time.sleep(0.1)\n                debugger = get_global_debugger()\n            debugger.ready_to_run = True\n        new_hidden_thread('ptvsd.unblock_debugger', unblock_debugger).start()\n    if kind == 'module':\n        run_module(address, name, *extra, **kwargs)\n    else:\n        run_file(address, name, *extra, **kwargs)\n\n\ndef run_main(address, name, kind, *extra, **kwargs):\n    addr = Address.from_raw(address)\n    sys.argv[:] = _run_main_argv(name, extra)\n    runner = kwargs.pop('_runner', no_debug_runner)\n    runner(addr, name, kind == 'module', *extra, **kwargs)\n\n\n########################\n# low-level functions\n\ndef run_module(address, modname, *extra, **kwargs):\n    \"\"\"Run pydevd for the given module.\"\"\"\n    addr = Address.from_raw(address)\n    if not addr.isserver:\n        kwargs['singlesession'] = True\n    run = kwargs.pop('_run', _run)\n    prog = kwargs.pop('_prog', sys.argv[0])\n    filename = modname + ':'\n    argv = _run_argv(addr, filename, extra, _prog=prog)\n    argv.insert(argv.index('--file'), '--module')\n    run(argv, addr, **kwargs)\n\n\ndef run_file(address, filename, *extra, **kwargs):\n    \"\"\"Run pydevd for the given Python file.\"\"\"\n    addr = Address.from_raw(address)\n    if not addr.isserver:\n        kwargs['singlesession'] = True\n    run = kwargs.pop('_run', _run)\n    prog = kwargs.pop('_prog', sys.argv[0])\n    argv = _run_argv(addr, filename, extra, _prog=prog)\n    run(argv, addr, **kwargs)\n\n\ndef _run_argv(address, filename, extra, _prog=sys.argv[0]):\n    \"\"\"Convert the given values to an argv that pydevd.main() supports.\"\"\"\n    if '--' in extra:\n        pydevd = list(extra[:extra.index('--')])\n        extra = list(extra[len(pydevd) + 1:])\n    else:\n        pydevd = []\n        extra = list(extra)\n\n    pydevd = _set_pydevd_defaults(pydevd)\n    host, port = address\n    argv = [\n        _prog,\n        '--port', str(port),\n    ]\n    if not address.isserver:\n        argv.extend([\n            '--client', host or 'localhost',\n        ])\n    return argv + pydevd + [\n        '--file', filename,\n    ] + extra\n\n\ndef _run_main_argv(filename, extra):\n    if '--' in extra:\n        pydevd = list(extra[:extra.index('--')])\n        extra = list(extra[len(pydevd) + 1:])\n    else:\n        extra = list(extra)\n    return [filename] + extra\n\n\ndef _run(argv, addr, _pydevd=pydevd, _install=install, **kwargs):\n    \"\"\"Start pydevd with the given commandline args.\"\"\"\n    #print(' '.join(argv))\n\n    # Pydevd assumes that the \"__main__\" module is the \"pydevd\" module\n    # and does some tricky stuff under that assumption.  For example,\n    # when the debugger starts up it calls save_main_module()\n    # (in pydevd_bundle/pydevd_utils.py).  That function explicitly sets\n    # sys.modules[\"pydevd\"] to sys.modules[\"__main__\"] and then sets\n    # the __main__ module to a new one.  This makes some sense since\n    # it gives the debugged script a fresh __main__ module.\n    #\n    # This complicates things for us since we are running a different\n    # file (i.e. this one) as the __main__ module.  Consequently,\n    # sys.modules[\"pydevd\"] gets set to ptvsd/__main__.py.  Subsequent\n    # imports of the \"pydevd\" module then return the wrong module.  We\n    # work around this by avoiding lazy imports of the \"pydevd\" module.\n    # We also replace the __main__ module with the \"pydevd\" module here.\n    if sys.modules['__main__'].__file__ != _pydevd.__file__:\n        sys.modules['__main___orig'] = sys.modules['__main__']\n        sys.modules['__main__'] = _pydevd\n\n    daemon = _install(_pydevd, addr, **kwargs)\n    sys.argv[:] = argv\n    try:\n        _pydevd.main()\n    except SystemExit as ex:\n        daemon.exitcode = int(ex.code)\n        raise\n", "path": "ptvsd/_local.py"}], "after_files": [{"content": "# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License. See LICENSE in the project root\n# for license information.\n\nimport sys\nimport time\n\nimport pydevd\nfrom _pydevd_bundle.pydevd_comm import get_global_debugger\n\nfrom ptvsd.pydevd_hooks import install\nfrom ptvsd.runner import run as no_debug_runner\nfrom ptvsd.socket import Address\nfrom ptvsd._util import new_hidden_thread\n\n\nPYDEVD_DEFAULTS = {\n    '--qt-support=auto',\n}\n\n\ndef _set_pydevd_defaults(pydevd_args):\n    args_to_append = []\n    for arg in PYDEVD_DEFAULTS:\n        if arg not in pydevd_args:\n            args_to_append.append(arg)\n    return pydevd_args + args_to_append\n\n\n########################\n# high-level functions\n\ndef debug_main(address, name, kind, *extra, **kwargs):\n    if not kwargs.pop('wait', False) and address.isserver:\n        def unblock_debugger():\n            debugger = get_global_debugger()\n            while debugger is None:\n                time.sleep(0.1)\n                debugger = get_global_debugger()\n            debugger.ready_to_run = True\n        new_hidden_thread('ptvsd.unblock_debugger', unblock_debugger).start()\n    if kind == 'module':\n        run_module(address, name, *extra, **kwargs)\n    else:\n        run_file(address, name, *extra, **kwargs)\n\n\ndef run_main(address, name, kind, *extra, **kwargs):\n    addr = Address.from_raw(address)\n    sys.argv[:] = _run_main_argv(name, extra)\n    runner = kwargs.pop('_runner', no_debug_runner)\n    runner(addr, name, kind == 'module', *extra, **kwargs)\n\n\n########################\n# low-level functions\n\ndef run_module(address, modname, *extra, **kwargs):\n    \"\"\"Run pydevd for the given module.\"\"\"\n    addr = Address.from_raw(address)\n    if not addr.isserver:\n        kwargs['singlesession'] = True\n    run = kwargs.pop('_run', _run)\n    prog = kwargs.pop('_prog', sys.argv[0])\n    filename = modname + ':'\n    argv = _run_argv(addr, filename, extra, _prog=prog)\n    argv.insert(argv.index('--file'), '--module')\n    run(argv, addr, **kwargs)\n\n\ndef run_file(address, filename, *extra, **kwargs):\n    \"\"\"Run pydevd for the given Python file.\"\"\"\n    addr = Address.from_raw(address)\n    if not addr.isserver:\n        kwargs['singlesession'] = True\n    run = kwargs.pop('_run', _run)\n    prog = kwargs.pop('_prog', sys.argv[0])\n    argv = _run_argv(addr, filename, extra, _prog=prog)\n    run(argv, addr, **kwargs)\n\n\ndef _run_argv(address, filename, extra, _prog=sys.argv[0]):\n    \"\"\"Convert the given values to an argv that pydevd.main() supports.\"\"\"\n    if '--' in extra:\n        pydevd = list(extra[:extra.index('--')])\n        extra = list(extra[len(pydevd) + 1:])\n    else:\n        pydevd = []\n        extra = list(extra)\n\n    pydevd = _set_pydevd_defaults(pydevd)\n    host, port = address\n    argv = [\n        _prog,\n        '--port', str(port),\n    ]\n    if not address.isserver:\n        argv.extend([\n            '--client', host or 'localhost',\n        ])\n    return argv + pydevd + [\n        '--file', filename,\n    ] + extra\n\n\ndef _run_main_argv(filename, extra):\n    if '--' in extra:\n        pydevd = list(extra[:extra.index('--')])\n        extra = list(extra[len(pydevd) + 1:])\n    else:\n        extra = list(extra)\n    return [filename] + extra\n\n\ndef _run(argv, addr, _pydevd=pydevd, _install=install, **kwargs):\n    \"\"\"Start pydevd with the given commandline args.\"\"\"\n    #print(' '.join(argv))\n\n    # Pydevd assumes that the \"__main__\" module is the \"pydevd\" module\n    # and does some tricky stuff under that assumption.  For example,\n    # when the debugger starts up it calls save_main_module()\n    # (in pydevd_bundle/pydevd_utils.py).  That function explicitly sets\n    # sys.modules[\"pydevd\"] to sys.modules[\"__main__\"] and then sets\n    # the __main__ module to a new one.  This makes some sense since\n    # it gives the debugged script a fresh __main__ module.\n    #\n    # This complicates things for us since we are running a different\n    # file (i.e. this one) as the __main__ module.  Consequently,\n    # sys.modules[\"pydevd\"] gets set to ptvsd/__main__.py.  Subsequent\n    # imports of the \"pydevd\" module then return the wrong module.  We\n    # work around this by avoiding lazy imports of the \"pydevd\" module.\n    # We also replace the __main__ module with the \"pydevd\" module here.\n    if sys.modules['__main__'].__file__ != _pydevd.__file__:\n        sys.modules['__main___orig'] = sys.modules['__main__']\n        sys.modules['__main__'] = _pydevd\n\n    daemon = _install(_pydevd, addr, **kwargs)\n    sys.argv[:] = argv\n    try:\n        _pydevd.main()\n    except SystemExit as ex:\n        daemon.exitcode = 0 if ex.code is None else int(ex.code)\n        raise\n", "path": "ptvsd/_local.py"}]}