persist across asynchronous calls, create a new `StackContext` (or
`ExceptionStackContext`), and make your asynchronous calls in a ``with``
block that references your `StackContext`.
+
+.. deprecated:: 5.1
+
+ The ``stack_context`` package is deprecated and will be removed in
+ Tornado 6.0.
"""
from __future__ import absolute_import, division, print_function
import sys
import threading
+import warnings
from tornado.util import raise_exc_info
and not necessary in most applications.
"""
def __init__(self, context_factory):
+ warnings.warn("StackContext is deprecated and will be removed in Tornado 6.0",
+ DeprecationWarning)
self.context_factory = context_factory
self.contexts = []
self.active = True
from tornado.platform.select import _Select
from tornado.stack_context import ExceptionStackContext, StackContext, wrap, NullContext
from tornado.testing import AsyncTestCase, bind_unused_port, ExpectLog, gen_test
-from tornado.test.util import unittest, skipIfNonUnix, skipOnTravis, skipBefore35, exec_test
+from tornado.test.util import (unittest, skipIfNonUnix, skipOnTravis,
+ skipBefore35, exec_test, ignore_deprecation)
try:
from concurrent import futures
self.assertNotIn('c2', self.active_contexts)
self.stop()
- with StackContext(functools.partial(self.context, 'c1')):
- wrapped = wrap(f1)
+ with ignore_deprecation():
+ with StackContext(functools.partial(self.context, 'c1')):
+ wrapped = wrap(f1)
- with StackContext(functools.partial(self.context, 'c2')):
- self.add_callback(wrapped)
+ with StackContext(functools.partial(self.context, 'c2')):
+ self.add_callback(wrapped)
self.wait()
self.assertNotIn('c2', self.active_contexts)
self.stop((foo, bar))
- with StackContext(functools.partial(self.context, 'c1')):
- wrapped = wrap(f1)
+ with ignore_deprecation():
+ with StackContext(functools.partial(self.context, 'c1')):
+ wrapped = wrap(f1)
- with StackContext(functools.partial(self.context, 'c2')):
- self.add_callback(wrapped, 1, bar=2)
+ with StackContext(functools.partial(self.context, 'c2')):
+ self.add_callback(wrapped, 1, bar=2)
result = self.wait()
self.assertEqual(result, (1, 2))