From a0640b3d6a30f815079e2233afcdb4d74719d11c Mon Sep 17 00:00:00 2001 From: Nicholas Bollweg Date: Sat, 14 Nov 2020 13:47:56 -0500 Subject: [PATCH] more work on removing asyncio patch --- jupyter_server/serverapp.py | 33 ++++++--------------------------- tests/test_files.py | 37 ++----------------------------------- 2 files changed, 8 insertions(+), 62 deletions(-) diff --git a/jupyter_server/serverapp.py b/jupyter_server/serverapp.py index 12f6134f36..1a32841cf4 100755 --- a/jupyter_server/serverapp.py +++ b/jupyter_server/serverapp.py @@ -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): @@ -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) diff --git a/tests/test_files.py b/tests/test_files.py index 268537d085..738b5879df 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -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]