Skip to content

Commit

Permalink
more work on removing asyncio patch
Browse files Browse the repository at this point in the history
  • Loading branch information
bollwyvl committed Nov 14, 2020
1 parent 480d6d6 commit a0640b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 62 deletions.
33 changes: 6 additions & 27 deletions jupyter_server/serverapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1604,32 +1604,12 @@ def init_httpserver(self):

@staticmethod
def _init_asyncio_patch():
return
# """set default asyncio policy to be compatible with tornado
# Tornado 6 (at least) is not compatible with the default
# asyncio implementation on Windows
# Pick the older SelectorEventLoopPolicy on Windows
# if the known-incompatible default policy is in use.
# do this as early as possible to make it a low priority and overrideable
# ref: https://github.com/tornadoweb/tornado/issues/2608
# FIXME: if/when tornado supports the defaults in asyncio,
# remove and bump tornado requirement for py38
# """
# if sys.platform.startswith("win") and sys.version_info >= (3, 8):
# import asyncio
# try:
# from asyncio import (
# WindowsProactorEventLoopPolicy,
# WindowsSelectorEventLoopPolicy,
# )
# except ImportError:
# pass
# # not affected
# else:
# if type(asyncio.get_event_loop_policy()) is WindowsProactorEventLoopPolicy:
# # WindowsProactorEventLoopPolicy is not compatible with tornado 6
# # fallback to the pre-3.8 default of Selector
# asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())
"""no longer needed with tornado 6.1"""
warnings.warn(
"""ServerApp._init_asyncio_patch called, and is longer needed for """
"""tornado 6.1+, and will be removed in a future release.""",
DeprecationWarning
)

@catch_config_error
def initialize(self, argv=None, find_extensions=True, new_httpserver=True):
Expand All @@ -1649,7 +1629,6 @@ def initialize(self, argv=None, find_extensions=True, new_httpserver=True):
If True, a tornado HTTPServer instance will be created and configured for the Server Web
Application. This will set the http_server attribute of this class.
"""
self._init_asyncio_patch()
# Parse command line, load ServerApp config files,
# and update ServerApp config.
super(ServerApp, self).initialize(argv)
Expand Down
37 changes: 2 additions & 35 deletions tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,47 +21,14 @@ def maybe_hidden(request):
return request.param



TIMEOUTS = dict(
# default is 20.0
connect_timeout=0.0,
# needs patch below
request_timeout=0.0
)

# HACK: shouldn't be overloading this

from jupyter_server.utils import url_path_join
import urllib.parse
from tornado.escape import url_escape

@pytest.fixture
def jp_fetch(jp_serverapp, http_server_client, jp_auth_header, jp_base_url):
def client_fetch(*parts, headers={}, params={}, **kwargs):
# Handle URL strings
path_url = url_escape(url_path_join(jp_base_url, *parts), plus=False)
params_url = urllib.parse.urlencode(params)
url = path_url + "?" + params_url
# Add auth keys to header
headers.update(jp_auth_header)
# Make request.
kwargs.setdefault("request_timeout", 20.0)
return http_server_client.fetch(
url, headers=headers, **kwargs
)
return client_fetch

# /HACK

async def fetch_expect_200(jp_fetch, *path_parts):
r = await jp_fetch('files', *path_parts, method='GET', **TIMEOUTS)
r = await jp_fetch('files', *path_parts, method='GET')
assert (r.body.decode() == path_parts[-1]), (path_parts, r.body)


async def fetch_expect_404(jp_fetch, *path_parts):
with pytest.raises(tornado.httpclient.HTTPClientError) as e:
r = await jp_fetch('files', *path_parts, method='GET', **TIMEOUTS)
print(r.body)
r = await jp_fetch('files', *path_parts, method='GET')
assert expected_http_error(e, 404), [path_parts, e]


Expand Down

0 comments on commit a0640b3

Please sign in to comment.