Skip to content
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

Handle deprecations in python 3.10 #3097

Merged
merged 9 commits into from
Jan 17, 2022

Conversation

bdarnell
Copy link
Member

Python 3.10 deprecated a number of things we rely on.

In the future, asyncio.get_event_loop will become an alias for get_running_loop, and anything related to supporting an event loop that is "current" but not running has been deprecated. This is very disruptive for us because that has been the normal mode of operation for tornado during application setup and many testing idioms. For now we need to get the test suite passing, so we catch deprecation warnings in various places and introduce new deprecation warnings to give users better message for things that we'll have to remove.

There are no intended changes in behavior except as it relates to deprecation warnings; applications that disable these warnings should be unaffected. In some future version of python, most tornado applications will need to be updated to use newer testing idioms; exactly what that means has not yet been determined.

The ssl module has also deprecated some modes of operation with insecure defaults. This PR updates tornado to use the newer modes, which results in a behavior change in some cases. Specifically, client-side usage of SSL will validate server certificates including hostname verification by default in all cases. Previously this was done by higher-level interfaces (like AsyncHTTPClient) but not by the lower-level IOStream or netutil interfaces. Applications that are affected by this should construct a ssl.SSLContext object with the appropriate configuration.

Fixes #3033

@Thorbenl
Copy link

Thorbenl commented Jan 3, 2022

Looks good to me! @bdarnell Thank you! Looking forward to the release.

Implicit creation of event loops has been deprecated in Python 3.10.
Since AnyThreadEventLoopPolicy modifies the rules for implicit loop
creation, it is also deprecated.
asyncio.get_event_loop and related methods are deprecated in python
3.10, so deprecate some IOLoop functionality to match. Specifically,
make_current, clear_current, and the IOLoop constructor are deprecated
in favor of initializing the asyncio event loop and calling
IOLoop.current(). (The IOLoop constructor is not deprecated if
make_current=False is used. This is useful in test frameworks but is
not expected to see general use).
Also avoid deprecated asyncio.get_event_loop in asyncio_test.
The interfaces defined by this class rely on an event loop being
"current" even though it is not running; this is incompatible with
the future of the asyncio module.

It's too big a task to rewrite all the tests right now, so just
swallow deprecation warnings for "no current event loop".
Pass a client/server flag to all SSL context creations. This is required
to avoid deprecations in Python 3.10. This is a behavior change for
client-side connections: certificate verification and hostname checks
are now enabled in more situations (previously, the high-level
interfaces would generally enforce these requirements but the low-level
interfaces like SSLIOStream did not).
@bdarnell bdarnell force-pushed the py310-deprecations branch 4 times, most recently from 5130b7d to e1a974b Compare January 16, 2022 22:06
These tests work in isolation but cause failures in the full suite
due to the leftover state of the asyncio event loop. Add cleanup to one
test and make another more tolerant of leftover state.
@bdarnell bdarnell force-pushed the py310-deprecations branch 11 times, most recently from eaff438 to 355b9ad Compare January 17, 2022 01:11
Now that compatibility between tornado and twisted is based on
asyncio, this test isn't very useful any more. It is broken by the
deprecations introduced in Python 3.10 and isn't worth reviving.
@bdarnell bdarnell force-pushed the py310-deprecations branch 4 times, most recently from 73612fb to 70908b6 Compare January 17, 2022 03:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A lot of deprecation warnings in python 3.10
2 participants