We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Stop on entry hangs the debugger
## Environment data

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

## Actual behavior

Note that you have to change the default for STOP_ON_ENTRY in wrapper.py#1198 to True.
Repros almost always on VS, but infrequently on VSC.

## Expected  behavior

Should run and break on entry

## Steps to reproduce:
For VS:
1. Change wrapper.py:1198 default for STOP_ON_ENTRY  to True.
2. Use F5 to start the debugger.

For VSC:
1. Set `stopOnEntry` in launch json.



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/ptvsd/debugger.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 
7 import ptvsd.log
8 from ptvsd._local import run_module, run_file, run_main
9 
10 
11 # TODO: not needed?
12 DONT_DEBUG = []
13 
14 LOCALHOST = 'localhost'
15 
16 RUNNERS = {
17     'module': run_module,  # python -m spam
18     'script': run_file,  # python spam.py
19     'code': run_file,  # python -c 'print("spam")'
20     None: run_file,  # catchall
21 }
22 
23 
24 def debug(filename, port_num, debug_id, debug_options, run_as,
25           _runners=RUNNERS, _extra=None, *args, **kwargs):
26 
27     ptvsd.log.to_file()
28     ptvsd.log.info('debug{0!r}', (filename, port_num, debug_id, debug_options, run_as))
29 
30     if _extra is None:
31         _extra = sys.argv[1:]
32     address = (LOCALHOST, port_num)
33     try:
34         run = _runners[run_as]
35     except KeyError:
36         # TODO: fail?
37         run = _runners[None]
38     if _extra:
39         args = _extra + list(args)
40     kwargs.setdefault('singlesession', True)
41     run(address, filename, *args, **kwargs)
42 
43 
44 def run(filename, port_num, run_as,
45         *args, **kwargs):
46 
47     ptvsd.log.to_file()
48     ptvsd.log.info('run{0!r}', (filename, port_num, run_as))
49 
50     address = (LOCALHOST, port_num)
51     run_main(address, filename, run_as, *args, **kwargs)
52
```
--- 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/src/ptvsd/debugger.py b/src/ptvsd/debugger.py
--- a/src/ptvsd/debugger.py
+++ b/src/ptvsd/debugger.py
@@ -2,50 +2,38 @@
 # Licensed under the MIT License. See LICENSE in the project root
 # for license information.
 
-import sys
-
 import ptvsd.log
-from ptvsd._local import run_module, run_file, run_main
-
-
-# TODO: not needed?
-DONT_DEBUG = []
+import ptvsd.options
+from ptvsd.__main__ import run_file, run_module, run_code
 
-LOCALHOST = 'localhost'
 
 RUNNERS = {
-    'module': run_module,  # python -m spam
-    'script': run_file,  # python spam.py
-    'code': run_file,  # python -c 'print("spam")'
-    None: run_file,  # catchall
+    'module': run_module,
+    'script': run_file,
+    'code': run_code,
 }
 
+# Not actually used, but VS will try to add entries to it.
+DONT_DEBUG = []
 
-def debug(filename, port_num, debug_id, debug_options, run_as,
-          _runners=RUNNERS, _extra=None, *args, **kwargs):
 
+# A legacy entrypoint for Visual Studio, to allow older versions to work with new ptvsd.
+# All new code should use the entrypoints in __main__ directly.
+def debug(filename, port_num, debug_id, debug_options, run_as):
     ptvsd.log.to_file()
     ptvsd.log.info('debug{0!r}', (filename, port_num, debug_id, debug_options, run_as))
 
-    if _extra is None:
-        _extra = sys.argv[1:]
-    address = (LOCALHOST, port_num)
     try:
-        run = _runners[run_as]
+        run = RUNNERS[run_as]
     except KeyError:
-        # TODO: fail?
-        run = _runners[None]
-    if _extra:
-        args = _extra + list(args)
-    kwargs.setdefault('singlesession', True)
-    run(address, filename, *args, **kwargs)
-
+        raise ValueError('run_as must be one of: {0!r}'.format(tuple(RUNNERS.keys())))
 
-def run(filename, port_num, run_as,
-        *args, **kwargs):
+    ptvsd.options.target_kind = 'file' if run_as == 'script' else run_as
+    ptvsd.options.target = filename
+    ptvsd.options.port = port_num
+    ptvsd.options.client = True
 
-    ptvsd.log.to_file()
-    ptvsd.log.info('run{0!r}', (filename, port_num, run_as))
+    # debug_id is ignored because it has no meaning in DAP.
+    # debug_options are ignored, because they will be passed later via DAP "launch" request.
 
-    address = (LOCALHOST, port_num)
-    run_main(address, filename, run_as, *args, **kwargs)
+    run()

{"golden_diff": "diff --git a/src/ptvsd/debugger.py b/src/ptvsd/debugger.py\n--- a/src/ptvsd/debugger.py\n+++ b/src/ptvsd/debugger.py\n@@ -2,50 +2,38 @@\n # Licensed under the MIT License. See LICENSE in the project root\n # for license information.\n \n-import sys\n-\n import ptvsd.log\n-from ptvsd._local import run_module, run_file, run_main\n-\n-\n-# TODO: not needed?\n-DONT_DEBUG = []\n+import ptvsd.options\n+from ptvsd.__main__ import run_file, run_module, run_code\n \n-LOCALHOST = 'localhost'\n \n RUNNERS = {\n-    'module': run_module,  # python -m spam\n-    'script': run_file,  # python spam.py\n-    'code': run_file,  # python -c 'print(\"spam\")'\n-    None: run_file,  # catchall\n+    'module': run_module,\n+    'script': run_file,\n+    'code': run_code,\n }\n \n+# Not actually used, but VS will try to add entries to it.\n+DONT_DEBUG = []\n \n-def debug(filename, port_num, debug_id, debug_options, run_as,\n-          _runners=RUNNERS, _extra=None, *args, **kwargs):\n \n+# A legacy entrypoint for Visual Studio, to allow older versions to work with new ptvsd.\n+# All new code should use the entrypoints in __main__ directly.\n+def debug(filename, port_num, debug_id, debug_options, run_as):\n     ptvsd.log.to_file()\n     ptvsd.log.info('debug{0!r}', (filename, port_num, debug_id, debug_options, run_as))\n \n-    if _extra is None:\n-        _extra = sys.argv[1:]\n-    address = (LOCALHOST, port_num)\n     try:\n-        run = _runners[run_as]\n+        run = RUNNERS[run_as]\n     except KeyError:\n-        # TODO: fail?\n-        run = _runners[None]\n-    if _extra:\n-        args = _extra + list(args)\n-    kwargs.setdefault('singlesession', True)\n-    run(address, filename, *args, **kwargs)\n-\n+        raise ValueError('run_as must be one of: {0!r}'.format(tuple(RUNNERS.keys())))\n \n-def run(filename, port_num, run_as,\n-        *args, **kwargs):\n+    ptvsd.options.target_kind = 'file' if run_as == 'script' else run_as\n+    ptvsd.options.target = filename\n+    ptvsd.options.port = port_num\n+    ptvsd.options.client = True\n \n-    ptvsd.log.to_file()\n-    ptvsd.log.info('run{0!r}', (filename, port_num, run_as))\n+    # debug_id is ignored because it has no meaning in DAP.\n+    # debug_options are ignored, because they will be passed later via DAP \"launch\" request.\n \n-    address = (LOCALHOST, port_num)\n-    run_main(address, filename, run_as, *args, **kwargs)\n+    run()\n", "issue": "Stop on entry hangs the debugger\n## Environment data\r\n\r\n- PTVSD version: master\r\n- OS and version: windows\r\n- Python version (& distribution if applicable, e.g. Anaconda): 3.6\r\n- Using VS Code or Visual Studio: VS or VSC\r\n\r\n## Actual behavior\r\n\r\nNote that you have to change the default for STOP_ON_ENTRY in wrapper.py#1198 to True.\r\nRepros almost always on VS, but infrequently on VSC.\r\n\r\n## Expected  behavior\r\n\r\nShould run and break on entry\r\n\r\n## Steps to reproduce:\r\nFor VS:\r\n1. Change wrapper.py:1198 default for STOP_ON_ENTRY  to True.\r\n2. Use F5 to start the debugger.\r\n\r\nFor VSC:\r\n1. Set `stopOnEntry` in launch json.\r\n\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\n\nimport ptvsd.log\nfrom ptvsd._local import run_module, run_file, run_main\n\n\n# TODO: not needed?\nDONT_DEBUG = []\n\nLOCALHOST = 'localhost'\n\nRUNNERS = {\n    'module': run_module,  # python -m spam\n    'script': run_file,  # python spam.py\n    'code': run_file,  # python -c 'print(\"spam\")'\n    None: run_file,  # catchall\n}\n\n\ndef debug(filename, port_num, debug_id, debug_options, run_as,\n          _runners=RUNNERS, _extra=None, *args, **kwargs):\n\n    ptvsd.log.to_file()\n    ptvsd.log.info('debug{0!r}', (filename, port_num, debug_id, debug_options, run_as))\n\n    if _extra is None:\n        _extra = sys.argv[1:]\n    address = (LOCALHOST, port_num)\n    try:\n        run = _runners[run_as]\n    except KeyError:\n        # TODO: fail?\n        run = _runners[None]\n    if _extra:\n        args = _extra + list(args)\n    kwargs.setdefault('singlesession', True)\n    run(address, filename, *args, **kwargs)\n\n\ndef run(filename, port_num, run_as,\n        *args, **kwargs):\n\n    ptvsd.log.to_file()\n    ptvsd.log.info('run{0!r}', (filename, port_num, run_as))\n\n    address = (LOCALHOST, port_num)\n    run_main(address, filename, run_as, *args, **kwargs)\n", "path": "src/ptvsd/debugger.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 ptvsd.log\nimport ptvsd.options\nfrom ptvsd.__main__ import run_file, run_module, run_code\n\n\nRUNNERS = {\n    'module': run_module,\n    'script': run_file,\n    'code': run_code,\n}\n\n# Not actually used, but VS will try to add entries to it.\nDONT_DEBUG = []\n\n\n# A legacy entrypoint for Visual Studio, to allow older versions to work with new ptvsd.\n# All new code should use the entrypoints in __main__ directly.\ndef debug(filename, port_num, debug_id, debug_options, run_as):\n    ptvsd.log.to_file()\n    ptvsd.log.info('debug{0!r}', (filename, port_num, debug_id, debug_options, run_as))\n\n    try:\n        run = RUNNERS[run_as]\n    except KeyError:\n        raise ValueError('run_as must be one of: {0!r}'.format(tuple(RUNNERS.keys())))\n\n    ptvsd.options.target_kind = 'file' if run_as == 'script' else run_as\n    ptvsd.options.target = filename\n    ptvsd.options.port = port_num\n    ptvsd.options.client = True\n\n    # debug_id is ignored because it has no meaning in DAP.\n    # debug_options are ignored, because they will be passed later via DAP \"launch\" request.\n\n    run()\n", "path": "src/ptvsd/debugger.py"}]}