-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tornado 6 compatibility #4449
Merged
Merged
tornado 6 compatibility #4449
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5712240
unpin tornado
minrk b1bd4e5
pip freeze on tornado
minrk 5828300
fix check for closed connection
minrk dcee710
patch gen.maybe_future for compatibility with tornado 6
minrk aa4ffe3
test with stable Python 3.7
minrk 71e1853
add test entries for tornado 4
minrk be35a37
gateway: compatibility with tornado 4
minrk d4e60d9
oops, no Python 2 on master
minrk 0b73ab6
changelog for 5.7.5 [ci skip]
minrk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,13 +12,31 @@ | |
import sys | ||
from distutils.version import LooseVersion | ||
|
||
try: | ||
from inspect import isawaitable | ||
except ImportError: | ||
def isawaitable(f): | ||
"""If isawaitable is undefined, nothing is awaitable""" | ||
return False | ||
|
||
try: | ||
from concurrent.futures import Future as ConcurrentFuture | ||
except ImportError: | ||
class ConcurrentFuture: | ||
"""If concurrent.futures isn't importable, nothing will be a c.f.Future""" | ||
pass | ||
|
||
try: | ||
from urllib.parse import quote, unquote, urlparse, urljoin | ||
from urllib.request import pathname2url | ||
except ImportError: | ||
from urllib import quote, unquote, pathname2url | ||
from urlparse import urlparse, urljoin | ||
|
||
# tornado.concurrent.Future is asyncio.Future | ||
# in tornado >=5 with Python 3 | ||
from tornado.concurrent import Future as TornadoFuture | ||
from tornado import gen | ||
from ipython_genutils import py3compat | ||
|
||
# UF_HIDDEN is a stat flag not defined in the stat module. | ||
|
@@ -306,3 +324,34 @@ def _check_pid_posix(pid): | |
check_pid = _check_pid_win32 | ||
else: | ||
check_pid = _check_pid_posix | ||
|
||
|
||
def maybe_future(obj): | ||
"""Like tornado's gen.maybe_future | ||
|
||
but more compatible with asyncio for recent versions | ||
of tornado | ||
""" | ||
if isinstance(obj, TornadoFuture): | ||
return obj | ||
elif isawaitable(obj): | ||
return asyncio.ensure_future(obj) | ||
elif isinstance(obj, ConcurrentFuture): | ||
return asyncio.wrap_future(obj) | ||
else: | ||
# not awaitable, wrap scalar in future | ||
f = TornadoFuture() | ||
f.set_result(obj) | ||
return f | ||
|
||
# monkeypatch tornado gen.maybe_future | ||
# on Python 3 | ||
# TODO: remove monkeypatch after backporting smaller fix to 5.x | ||
try: | ||
import asyncio | ||
except ImportError: | ||
pass | ||
else: | ||
import tornado.gen | ||
tornado.gen.maybe_future = maybe_future | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very nice. I had also found that |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW - I had found the similar change was necessary via
ws_connection
.