# Buggy code
def unlisten(self):
    """Stop listening on ports. The server will no longer be usable after
    calling this function.

    Returns:
        None

    """
    self._http.close_all_connections()
    self._http.stop()


# Traceback (RuntimeError)
-- Docs: https://docs.pytest.org/en/latest/warnings.html
----------- generated xml file: C:\projects\bokeh\test_results.xml ------------
= 1 failed, 3444 passed, 1 skipped, 981 deselected, 78 warnings in 241.84 seconds =
Task was destroyed but it is pending!
task: <Task pending coro=<RequestHandler._execute() running at C:\Miniconda36-x64\lib\site-packages\tornado\web.py:1699> wait_for=<Future pending cb=[coroutine.<locals>.wrapper.<locals>.<lambda>() at C:\Miniconda36-x64\lib\site-packages\tornado\gen.py:226, <1 more>, <TaskWakeupMethWrapper object at 0x000000A280615888>()]> cb=[_HandlerDelegate.execute.<locals>.<lambda>() at C:\Miniconda36-x64\lib\site-packages\tornado\web.py:2329]>
Exception ignored in: <generator object send at 0x000000A28051F5C8>
Traceback (most recent call last):
File "C:\projects\bokeh\bokeh\protocol\message.py", line 281, in send
raise gen.Return(sent)
File "C:\Miniconda36-x64\lib\site-packages\tornado\locks.py", line 282, in __exit__
self._obj.release()
File "C:\Miniconda36-x64\lib\site-packages\tornado\locks.py", line 482, in release
super(BoundedSemaphore, self).release()
File "C:\Miniconda36-x64\lib\site-packages\tornado\locks.py", line 411, in release
waiter.set_result(_ReleasingContextManager(self))
File "C:\Miniconda36-x64\lib\asyncio\base_events.py", line 575, in call_soon
self._check_closed()
File "C:\Miniconda36-x64\lib\asyncio\base_events.py", line 358, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Future exception was never retrieved
future: <Future finished exception=WebSocketClosedError()>
Traceback (most recent call last):
File "C:\Miniconda36-x64\lib\site-packages\tornado\websocket.py", line 1100, in wrapper
await fut
tornado.iostream.StreamClosedError: Stream is closed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Miniconda36-x64\lib\site-packages\tornado\gen.py", line 736, in run
yielded = self.gen.throw(*exc_info)  # type: ignore
File "C:\projects\bokeh\bokeh\server\views\ws.py", line 269, in write_message
yield super(WSHandler, self).write_message(message, binary)
File "C:\Miniconda36-x64\lib\site-packages\tornado\gen.py", line 729, in run
value = future.result()
File "C:\Miniconda36-x64\lib\site-packages\tornado\websocket.py", line 1102, in wrapper
raise WebSocketClosedError()
tornado.websocket.WebSocketClosedError
Exception ignored in: <generator object _needs_document_lock_wrapper at 0x000000A280606B48>
Traceback (most recent call last):
File "C:\projects\bokeh\bokeh\server\session.py", line 78, in _needs_document_lock_wrapper
yield p
File "C:\Miniconda36-x64\lib\site-packages\tornado\locks.py", line 282, in __exit__
self._obj.release()
File "C:\Miniconda36-x64\lib\site-packages\tornado\locks.py", line 482, in release
super(BoundedSemaphore, self).release()
File "C:\Miniconda36-x64\lib\site-packages\tornado\locks.py", line 411, in release
waiter.set_result(_ReleasingContextManager(self))
File "C:\Miniconda36-x64\lib\asyncio\base_events.py", line 575, in call_soon
self._check_closed()
File "C:\Miniconda36-x64\lib\asyncio\base_events.py", line 358, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Command exited with code 1
$wc = New-Object 'System.Net.WebClient'

# Fixed code
def unlisten(self):
    """Stop listening on ports. The server will no longer be usable after
    calling this function.

    Returns:
        None

    """
    yield self._http.close_all_connections()
    self._http.stop()