We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Tooltip hangs when expanding sys.modules
![image](https://user-images.githubusercontent.com/3840081/37120086-342e50e2-220e-11e8-8044-5ce72ad0f6b6.png)

For VS there is a 'timeout' field that is set (for evaluate, variable enumeration, etc), and this must be honored to have better UI experience. See this request for example:
```
 1> [DebugAdapter] --> C (variables-11): {"command":"variables","arguments":{"variablesReference":12,"timeout":5000},"seq":11,"type":"request"}
```

--- 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/untangle.py`
Content:
```
1 #!/usr/bin/env python
2 
3 """
4  untangle
5 
6  Converts xml to python objects.
7 
8  The only method you need to call is parse()
9 
10  Partially inspired by xml2obj
11  (http://code.activestate.com/recipes/149368-xml2obj/)
12 
13  Author: Christian Stefanescu (http://0chris.com)
14  License: MIT License - http://www.opensource.org/licenses/mit-license.php
15 """
16 import os
17 import keyword
18 from xml.sax import make_parser, handler
19 try:
20     from StringIO import StringIO
21 except ImportError:
22     from io import StringIO
23 try:
24     from types import StringTypes
25 
26     def is_string(x):
27         return isinstance(x, StringTypes)
28 except ImportError:
29     def is_string(x):
30         return isinstance(x, str)
31 
32 __version__ = '1.1.1'
33 
34 
35 class Element(object):
36     """
37     Representation of an XML element.
38     """
39     def __init__(self, name, attributes):
40         self._name = name
41         self._attributes = attributes
42         self.children = []
43         self.is_root = False
44         self.cdata = ''
45 
46     def add_child(self, element):
47         """
48         Store child elements.
49         """
50         self.children.append(element)
51 
52     def add_cdata(self, cdata):
53         """
54         Store cdata
55         """
56         self.cdata = self.cdata + cdata
57 
58     def get_attribute(self, key):
59         """
60         Get attributes by key
61         """
62         return self._attributes.get(key)
63 
64     def get_elements(self, name=None):
65         """
66         Find a child element by name
67         """
68         if name:
69             return [e for e in self.children if e._name == name]
70         else:
71             return self.children
72 
73     def __getitem__(self, key):
74         return self.get_attribute(key)
75 
76     def __getattr__(self, key):
77         matching_children = [x for x in self.children if x._name == key]
78         if matching_children:
79             if len(matching_children) == 1:
80                 self.__dict__[key] = matching_children[0]
81                 return matching_children[0]
82             else:
83                 self.__dict__[key] = matching_children
84                 return matching_children
85         else:
86             raise AttributeError(
87                 "'%s' has no attribute '%s'" % (self._name, key)
88             )
89 
90     def __hasattribute__(self, name):
91         if name in self.__dict__:
92             return True
93         return any(self.children, lambda x: x._name == name)
94 
95     def __iter__(self):
96         yield self
97 
98     def __str__(self):
99         return (
100             "Element <%s> with attributes %s, children %s and cdata %s" %
101             (self._name, self._attributes, self.children, self.cdata)
102         )
103 
104     def __repr__(self):
105         return (
106             "Element(name = %s, attributes = %s, cdata = %s)" %
107             (self._name, self._attributes, self.cdata)
108         )
109 
110     def __nonzero__(self):
111         return self.is_root or self._name is not None
112 
113     def __eq__(self, val):
114         return self.cdata == val
115 
116     def __dir__(self):
117         children_names = [x._name for x in self.children]
118         return children_names
119 
120     def __len__(self):
121         return len(self.children)
122 
123     def __contains__(self, key):
124         return key in dir(self)
125 
126 
127 class Handler(handler.ContentHandler):
128     """
129     SAX handler which creates the Python object structure out of ``Element``s
130     """
131     def __init__(self):
132         self.root = Element(None, None)
133         self.root.is_root = True
134         self.elements = []
135 
136     def startElement(self, name, attributes):
137         name = name.replace('-', '_')
138         name = name.replace('.', '_')
139         name = name.replace(':', '_')
140 
141         # adding trailing _ for keywords
142         if keyword.iskeyword(name):
143             name += '_'
144 
145         attrs = dict()
146         for k, v in attributes.items():
147             attrs[k] = v
148         element = Element(name, attrs)
149         if len(self.elements) > 0:
150             self.elements[-1].add_child(element)
151         else:
152             self.root.add_child(element)
153         self.elements.append(element)
154 
155     def endElement(self, name):
156         self.elements.pop()
157 
158     def characters(self, cdata):
159         self.elements[-1].add_cdata(cdata)
160 
161 
162 def parse(filename, **parser_features):
163     """
164     Interprets the given string as a filename, URL or XML data string,
165     parses it and returns a Python object which represents the given
166     document.
167 
168     Extra arguments to this function are treated as feature values to pass
169     to ``parser.setFeature()``. For example, ``feature_external_ges=False``
170     will set ``xml.sax.handler.feature_external_ges`` to False, disabling
171     the parser's inclusion of external general (text) entities such as DTDs.
172 
173     Raises ``ValueError`` if the first argument is None / empty string.
174 
175     Raises ``AttributeError`` if a requested xml.sax feature is not found in
176     ``xml.sax.handler``.
177 
178     Raises ``xml.sax.SAXParseException`` if something goes wrong
179     during parsing.
180     """
181     if (filename is None or (is_string(filename) and filename.strip()) == ''):
182         raise ValueError('parse() takes a filename, URL or XML string')
183     parser = make_parser()
184     for feature, value in parser_features.items():
185         parser.setFeature(getattr(handler, feature), value)
186     sax_handler = Handler()
187     parser.setContentHandler(sax_handler)
188     if is_string(filename) and (os.path.exists(filename) or is_url(filename)):
189         parser.parse(filename)
190     else:
191         if hasattr(filename, 'read'):
192             parser.parse(filename)
193         else:
194             parser.parse(StringIO(filename))
195 
196     return sax_handler.root
197 
198 
199 def is_url(string):
200     """
201     Checks if the given string starts with 'http(s)'.
202     """
203     try:
204         return string.startswith('http://') or string.startswith('https://')
205     except AttributeError:
206         return False
207 
208 # vim: set expandtab ts=4 sw=4:
209
```
--- 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/untangle.py b/ptvsd/untangle.py
--- a/ptvsd/untangle.py
+++ b/ptvsd/untangle.py
@@ -185,7 +185,11 @@
         parser.setFeature(getattr(handler, feature), value)
     sax_handler = Handler()
     parser.setContentHandler(sax_handler)
-    if is_string(filename) and (os.path.exists(filename) or is_url(filename)):
+    try:
+        is_filename = is_string(filename) and (os.path.exists(filename) or is_url(filename))
+    except ValueError:
+        is_filename = False
+    if is_filename:
         parser.parse(filename)
     else:
         if hasattr(filename, 'read'):

{"golden_diff": "diff --git a/ptvsd/untangle.py b/ptvsd/untangle.py\n--- a/ptvsd/untangle.py\n+++ b/ptvsd/untangle.py\n@@ -185,7 +185,11 @@\n         parser.setFeature(getattr(handler, feature), value)\n     sax_handler = Handler()\n     parser.setContentHandler(sax_handler)\n-    if is_string(filename) and (os.path.exists(filename) or is_url(filename)):\n+    try:\n+        is_filename = is_string(filename) and (os.path.exists(filename) or is_url(filename))\n+    except ValueError:\n+        is_filename = False\n+    if is_filename:\n         parser.parse(filename)\n     else:\n         if hasattr(filename, 'read'):\n", "issue": "Tooltip hangs when expanding sys.modules\n![image](https://user-images.githubusercontent.com/3840081/37120086-342e50e2-220e-11e8-8044-5ce72ad0f6b6.png)\r\n\r\nFor VS there is a 'timeout' field that is set (for evaluate, variable enumeration, etc), and this must be honored to have better UI experience. See this request for example:\r\n```\r\n 1> [DebugAdapter] --> C (variables-11): {\"command\":\"variables\",\"arguments\":{\"variablesReference\":12,\"timeout\":5000},\"seq\":11,\"type\":\"request\"}\r\n```\n", "before_files": [{"content": "#!/usr/bin/env python\n\n\"\"\"\n untangle\n\n Converts xml to python objects.\n\n The only method you need to call is parse()\n\n Partially inspired by xml2obj\n (http://code.activestate.com/recipes/149368-xml2obj/)\n\n Author: Christian Stefanescu (http://0chris.com)\n License: MIT License - http://www.opensource.org/licenses/mit-license.php\n\"\"\"\nimport os\nimport keyword\nfrom xml.sax import make_parser, handler\ntry:\n    from StringIO import StringIO\nexcept ImportError:\n    from io import StringIO\ntry:\n    from types import StringTypes\n\n    def is_string(x):\n        return isinstance(x, StringTypes)\nexcept ImportError:\n    def is_string(x):\n        return isinstance(x, str)\n\n__version__ = '1.1.1'\n\n\nclass Element(object):\n    \"\"\"\n    Representation of an XML element.\n    \"\"\"\n    def __init__(self, name, attributes):\n        self._name = name\n        self._attributes = attributes\n        self.children = []\n        self.is_root = False\n        self.cdata = ''\n\n    def add_child(self, element):\n        \"\"\"\n        Store child elements.\n        \"\"\"\n        self.children.append(element)\n\n    def add_cdata(self, cdata):\n        \"\"\"\n        Store cdata\n        \"\"\"\n        self.cdata = self.cdata + cdata\n\n    def get_attribute(self, key):\n        \"\"\"\n        Get attributes by key\n        \"\"\"\n        return self._attributes.get(key)\n\n    def get_elements(self, name=None):\n        \"\"\"\n        Find a child element by name\n        \"\"\"\n        if name:\n            return [e for e in self.children if e._name == name]\n        else:\n            return self.children\n\n    def __getitem__(self, key):\n        return self.get_attribute(key)\n\n    def __getattr__(self, key):\n        matching_children = [x for x in self.children if x._name == key]\n        if matching_children:\n            if len(matching_children) == 1:\n                self.__dict__[key] = matching_children[0]\n                return matching_children[0]\n            else:\n                self.__dict__[key] = matching_children\n                return matching_children\n        else:\n            raise AttributeError(\n                \"'%s' has no attribute '%s'\" % (self._name, key)\n            )\n\n    def __hasattribute__(self, name):\n        if name in self.__dict__:\n            return True\n        return any(self.children, lambda x: x._name == name)\n\n    def __iter__(self):\n        yield self\n\n    def __str__(self):\n        return (\n            \"Element <%s> with attributes %s, children %s and cdata %s\" %\n            (self._name, self._attributes, self.children, self.cdata)\n        )\n\n    def __repr__(self):\n        return (\n            \"Element(name = %s, attributes = %s, cdata = %s)\" %\n            (self._name, self._attributes, self.cdata)\n        )\n\n    def __nonzero__(self):\n        return self.is_root or self._name is not None\n\n    def __eq__(self, val):\n        return self.cdata == val\n\n    def __dir__(self):\n        children_names = [x._name for x in self.children]\n        return children_names\n\n    def __len__(self):\n        return len(self.children)\n\n    def __contains__(self, key):\n        return key in dir(self)\n\n\nclass Handler(handler.ContentHandler):\n    \"\"\"\n    SAX handler which creates the Python object structure out of ``Element``s\n    \"\"\"\n    def __init__(self):\n        self.root = Element(None, None)\n        self.root.is_root = True\n        self.elements = []\n\n    def startElement(self, name, attributes):\n        name = name.replace('-', '_')\n        name = name.replace('.', '_')\n        name = name.replace(':', '_')\n\n        # adding trailing _ for keywords\n        if keyword.iskeyword(name):\n            name += '_'\n\n        attrs = dict()\n        for k, v in attributes.items():\n            attrs[k] = v\n        element = Element(name, attrs)\n        if len(self.elements) > 0:\n            self.elements[-1].add_child(element)\n        else:\n            self.root.add_child(element)\n        self.elements.append(element)\n\n    def endElement(self, name):\n        self.elements.pop()\n\n    def characters(self, cdata):\n        self.elements[-1].add_cdata(cdata)\n\n\ndef parse(filename, **parser_features):\n    \"\"\"\n    Interprets the given string as a filename, URL or XML data string,\n    parses it and returns a Python object which represents the given\n    document.\n\n    Extra arguments to this function are treated as feature values to pass\n    to ``parser.setFeature()``. For example, ``feature_external_ges=False``\n    will set ``xml.sax.handler.feature_external_ges`` to False, disabling\n    the parser's inclusion of external general (text) entities such as DTDs.\n\n    Raises ``ValueError`` if the first argument is None / empty string.\n\n    Raises ``AttributeError`` if a requested xml.sax feature is not found in\n    ``xml.sax.handler``.\n\n    Raises ``xml.sax.SAXParseException`` if something goes wrong\n    during parsing.\n    \"\"\"\n    if (filename is None or (is_string(filename) and filename.strip()) == ''):\n        raise ValueError('parse() takes a filename, URL or XML string')\n    parser = make_parser()\n    for feature, value in parser_features.items():\n        parser.setFeature(getattr(handler, feature), value)\n    sax_handler = Handler()\n    parser.setContentHandler(sax_handler)\n    if is_string(filename) and (os.path.exists(filename) or is_url(filename)):\n        parser.parse(filename)\n    else:\n        if hasattr(filename, 'read'):\n            parser.parse(filename)\n        else:\n            parser.parse(StringIO(filename))\n\n    return sax_handler.root\n\n\ndef is_url(string):\n    \"\"\"\n    Checks if the given string starts with 'http(s)'.\n    \"\"\"\n    try:\n        return string.startswith('http://') or string.startswith('https://')\n    except AttributeError:\n        return False\n\n# vim: set expandtab ts=4 sw=4:\n", "path": "ptvsd/untangle.py"}], "after_files": [{"content": "#!/usr/bin/env python\n\n\"\"\"\n untangle\n\n Converts xml to python objects.\n\n The only method you need to call is parse()\n\n Partially inspired by xml2obj\n (http://code.activestate.com/recipes/149368-xml2obj/)\n\n Author: Christian Stefanescu (http://0chris.com)\n License: MIT License - http://www.opensource.org/licenses/mit-license.php\n\"\"\"\nimport os\nimport keyword\nfrom xml.sax import make_parser, handler\ntry:\n    from StringIO import StringIO\nexcept ImportError:\n    from io import StringIO\ntry:\n    from types import StringTypes\n\n    def is_string(x):\n        return isinstance(x, StringTypes)\nexcept ImportError:\n    def is_string(x):\n        return isinstance(x, str)\n\n__version__ = '1.1.1'\n\n\nclass Element(object):\n    \"\"\"\n    Representation of an XML element.\n    \"\"\"\n    def __init__(self, name, attributes):\n        self._name = name\n        self._attributes = attributes\n        self.children = []\n        self.is_root = False\n        self.cdata = ''\n\n    def add_child(self, element):\n        \"\"\"\n        Store child elements.\n        \"\"\"\n        self.children.append(element)\n\n    def add_cdata(self, cdata):\n        \"\"\"\n        Store cdata\n        \"\"\"\n        self.cdata = self.cdata + cdata\n\n    def get_attribute(self, key):\n        \"\"\"\n        Get attributes by key\n        \"\"\"\n        return self._attributes.get(key)\n\n    def get_elements(self, name=None):\n        \"\"\"\n        Find a child element by name\n        \"\"\"\n        if name:\n            return [e for e in self.children if e._name == name]\n        else:\n            return self.children\n\n    def __getitem__(self, key):\n        return self.get_attribute(key)\n\n    def __getattr__(self, key):\n        matching_children = [x for x in self.children if x._name == key]\n        if matching_children:\n            if len(matching_children) == 1:\n                self.__dict__[key] = matching_children[0]\n                return matching_children[0]\n            else:\n                self.__dict__[key] = matching_children\n                return matching_children\n        else:\n            raise AttributeError(\n                \"'%s' has no attribute '%s'\" % (self._name, key)\n            )\n\n    def __hasattribute__(self, name):\n        if name in self.__dict__:\n            return True\n        return any(self.children, lambda x: x._name == name)\n\n    def __iter__(self):\n        yield self\n\n    def __str__(self):\n        return (\n            \"Element <%s> with attributes %s, children %s and cdata %s\" %\n            (self._name, self._attributes, self.children, self.cdata)\n        )\n\n    def __repr__(self):\n        return (\n            \"Element(name = %s, attributes = %s, cdata = %s)\" %\n            (self._name, self._attributes, self.cdata)\n        )\n\n    def __nonzero__(self):\n        return self.is_root or self._name is not None\n\n    def __eq__(self, val):\n        return self.cdata == val\n\n    def __dir__(self):\n        children_names = [x._name for x in self.children]\n        return children_names\n\n    def __len__(self):\n        return len(self.children)\n\n    def __contains__(self, key):\n        return key in dir(self)\n\n\nclass Handler(handler.ContentHandler):\n    \"\"\"\n    SAX handler which creates the Python object structure out of ``Element``s\n    \"\"\"\n    def __init__(self):\n        self.root = Element(None, None)\n        self.root.is_root = True\n        self.elements = []\n\n    def startElement(self, name, attributes):\n        name = name.replace('-', '_')\n        name = name.replace('.', '_')\n        name = name.replace(':', '_')\n\n        # adding trailing _ for keywords\n        if keyword.iskeyword(name):\n            name += '_'\n\n        attrs = dict()\n        for k, v in attributes.items():\n            attrs[k] = v\n        element = Element(name, attrs)\n        if len(self.elements) > 0:\n            self.elements[-1].add_child(element)\n        else:\n            self.root.add_child(element)\n        self.elements.append(element)\n\n    def endElement(self, name):\n        self.elements.pop()\n\n    def characters(self, cdata):\n        self.elements[-1].add_cdata(cdata)\n\n\ndef parse(filename, **parser_features):\n    \"\"\"\n    Interprets the given string as a filename, URL or XML data string,\n    parses it and returns a Python object which represents the given\n    document.\n\n    Extra arguments to this function are treated as feature values to pass\n    to ``parser.setFeature()``. For example, ``feature_external_ges=False``\n    will set ``xml.sax.handler.feature_external_ges`` to False, disabling\n    the parser's inclusion of external general (text) entities such as DTDs.\n\n    Raises ``ValueError`` if the first argument is None / empty string.\n\n    Raises ``AttributeError`` if a requested xml.sax feature is not found in\n    ``xml.sax.handler``.\n\n    Raises ``xml.sax.SAXParseException`` if something goes wrong\n    during parsing.\n    \"\"\"\n    if (filename is None or (is_string(filename) and filename.strip()) == ''):\n        raise ValueError('parse() takes a filename, URL or XML string')\n    parser = make_parser()\n    for feature, value in parser_features.items():\n        parser.setFeature(getattr(handler, feature), value)\n    sax_handler = Handler()\n    parser.setContentHandler(sax_handler)\n    try:\n        is_filename = is_string(filename) and (os.path.exists(filename) or is_url(filename))\n    except ValueError:\n        is_filename = False\n    if is_filename:\n        parser.parse(filename)\n    else:\n        if hasattr(filename, 'read'):\n            parser.parse(filename)\n        else:\n            parser.parse(StringIO(filename))\n\n    return sax_handler.root\n\n\ndef is_url(string):\n    \"\"\"\n    Checks if the given string starts with 'http(s)'.\n    \"\"\"\n    try:\n        return string.startswith('http://') or string.startswith('https://')\n    except AttributeError:\n        return False\n\n# vim: set expandtab ts=4 sw=4:\n", "path": "ptvsd/untangle.py"}]}