mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Fixes 9903: test_concurrent_futures writes on stderr
This commit is contained in:
parent
5ad8ed5f26
commit
1e2ae4f054
2 changed files with 30 additions and 19 deletions
|
@ -40,9 +40,8 @@ _STATE_TO_DESCRIPTION_MAP = {
|
||||||
|
|
||||||
# Logger for internal use by the futures package.
|
# Logger for internal use by the futures package.
|
||||||
LOGGER = logging.getLogger("concurrent.futures")
|
LOGGER = logging.getLogger("concurrent.futures")
|
||||||
_handler = logging.StreamHandler()
|
STDERR_HANDLER = logging.StreamHandler()
|
||||||
LOGGER.addHandler(_handler)
|
LOGGER.addHandler(STDERR_HANDLER)
|
||||||
del _handler
|
|
||||||
|
|
||||||
class Error(Exception):
|
class Error(Exception):
|
||||||
"""Base class for all future-related exceptions."""
|
"""Base class for all future-related exceptions."""
|
||||||
|
|
|
@ -9,6 +9,8 @@ test.support.import_module('multiprocessing.synchronize')
|
||||||
# without thread support.
|
# without thread support.
|
||||||
test.support.import_module('threading')
|
test.support.import_module('threading')
|
||||||
|
|
||||||
|
import io
|
||||||
|
import logging
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
|
@ -21,7 +23,8 @@ if sys.platform.startswith('win'):
|
||||||
|
|
||||||
from concurrent import futures
|
from concurrent import futures
|
||||||
from concurrent.futures._base import (
|
from concurrent.futures._base import (
|
||||||
PENDING, RUNNING, CANCELLED, CANCELLED_AND_NOTIFIED, FINISHED, Future, wait)
|
PENDING, RUNNING, CANCELLED, CANCELLED_AND_NOTIFIED, FINISHED, Future,
|
||||||
|
LOGGER, STDERR_HANDLER, wait)
|
||||||
import concurrent.futures.process
|
import concurrent.futures.process
|
||||||
|
|
||||||
def create_future(state=PENDING, exception=None, result=None):
|
def create_future(state=PENDING, exception=None, result=None):
|
||||||
|
@ -617,24 +620,33 @@ class FutureTests(unittest.TestCase):
|
||||||
self.assertTrue(was_cancelled)
|
self.assertTrue(was_cancelled)
|
||||||
|
|
||||||
def test_done_callback_raises(self):
|
def test_done_callback_raises(self):
|
||||||
raising_was_called = False
|
LOGGER.removeHandler(STDERR_HANDLER)
|
||||||
fn_was_called = False
|
logging_stream = io.StringIO()
|
||||||
|
handler = logging.StreamHandler(logging_stream)
|
||||||
|
LOGGER.addHandler(handler)
|
||||||
|
try:
|
||||||
|
raising_was_called = False
|
||||||
|
fn_was_called = False
|
||||||
|
|
||||||
def raising_fn(callback_future):
|
def raising_fn(callback_future):
|
||||||
nonlocal raising_was_called
|
nonlocal raising_was_called
|
||||||
raising_was_called = True
|
raising_was_called = True
|
||||||
raise Exception('doh!')
|
raise Exception('doh!')
|
||||||
|
|
||||||
def fn(callback_future):
|
def fn(callback_future):
|
||||||
nonlocal fn_was_called
|
nonlocal fn_was_called
|
||||||
fn_was_called = True
|
fn_was_called = True
|
||||||
|
|
||||||
f = Future()
|
f = Future()
|
||||||
f.add_done_callback(raising_fn)
|
f.add_done_callback(raising_fn)
|
||||||
f.add_done_callback(fn)
|
f.add_done_callback(fn)
|
||||||
f.set_result(5)
|
f.set_result(5)
|
||||||
self.assertTrue(raising_was_called)
|
self.assertTrue(raising_was_called)
|
||||||
self.assertTrue(fn_was_called)
|
self.assertTrue(fn_was_called)
|
||||||
|
self.assertIn('Exception: doh!', logging_stream.getvalue())
|
||||||
|
finally:
|
||||||
|
LOGGER.removeHandler(handler)
|
||||||
|
LOGGER.addHandler(STDERR_HANDLER)
|
||||||
|
|
||||||
def test_done_callback_already_successful(self):
|
def test_done_callback_already_successful(self):
|
||||||
callback_result = None
|
callback_result = None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue