File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Lib/test/test_concurrent_futures Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 22import contextlib
33import io
44import os
5+ import subprocess
56import sys
7+ import textwrap
68import time
79import unittest
810from concurrent .futures .interpreter import BrokenInterpreterPool
@@ -457,6 +459,38 @@ def test_free_reference(self):
457459 # Weak references don't cross between interpreters.
458460 raise unittest .SkipTest ('not applicable' )
459461
462+ def test_import_interpreter_pool_executor (self ):
463+ # Test the import behavior normally if _interpreters is unavailable.
464+ code = textwrap .dedent (f"""
465+ from concurrent import futures
466+ import sys
467+ # Set it to None to emulate the case when _interpreter is unavailable.
468+ futures._interpreters = None
469+
470+ try:
471+ futures.InterpreterPoolExecutor
472+ except AttributeError:
473+ pass
474+ else:
475+ print('AttributeError not raised!', file=sys.stderr)
476+ sys.exit(1)
477+
478+ try:
479+ from concurrent.futures import InterpreterPoolExecutor
480+ except ImportError:
481+ pass
482+ else:
483+ print('ImportError not raised!', file=sys.stderr)
484+ sys.exit(1)
485+
486+
487+ from concurrent.futures import *
488+ """ )
489+
490+ cmd = [sys .executable , '-c' , code ]
491+ p = subprocess .run (cmd , capture_output = True )
492+ self .assertEqual (p .returncode , 0 , p .stderr .decode ())
493+
460494
461495class AsyncioTest (InterpretersMixin , testasyncio_utils .TestCase ):
462496
You can’t perform that action at this time.
0 commit comments