66import collections .abc
77import contextlib
88import errno
9- import faulthandler
109import fnmatch
1110import functools
12- import gc
1311import glob
1412import importlib
1513import importlib .util
1614import os
1715import platform
1816import re
19- import shutil
2017import stat
2118import struct
2219import subprocess
2320import sys
2421import sysconfig
25- import tempfile
2622import _thread
2723import threading
2824import time
@@ -439,6 +435,7 @@ def _longpath(path):
439435 _rmdir = os .rmdir
440436
441437 def _rmtree (path ):
438+ import shutil
442439 try :
443440 shutil .rmtree (path )
444441 return
@@ -891,6 +888,7 @@ def temp_dir(path=None, quiet=False):
891888 created, only a warning is issued.
892889
893890 """
891+ import tempfile
894892 dir_created = False
895893 if path is None :
896894 path = tempfile .mkdtemp ()
@@ -1436,6 +1434,7 @@ def gc_collect():
14361434 longer than expected. This function tries its best to force all garbage
14371435 objects to disappear.
14381436 """
1437+ import gc
14391438 gc .collect ()
14401439 if is_jython :
14411440 time .sleep (0.1 )
@@ -1444,6 +1443,7 @@ def gc_collect():
14441443
14451444@contextlib .contextmanager
14461445def disable_gc ():
1446+ import gc
14471447 have_gc = gc .isenabled ()
14481448 gc .disable ()
14491449 try :
@@ -2136,6 +2136,7 @@ def reap_children():
21362136
21372137@contextlib .contextmanager
21382138def start_threads (threads , unlock = None ):
2139+ import faulthandler
21392140 threads = list (threads )
21402141 started = []
21412142 try :
@@ -2401,6 +2402,7 @@ def call_link(self, *args, returncode=0):
24012402
24022403_can_xattr = None
24032404def can_xattr ():
2405+ import tempfile
24042406 global _can_xattr
24052407 if _can_xattr is not None :
24062408 return _can_xattr
@@ -2445,6 +2447,7 @@ def skip_if_pgo_task(test):
24452447
24462448def fs_is_case_insensitive (directory ):
24472449 """Detects if the file system for the specified directory is case-insensitive."""
2450+ import tempfile
24482451 with tempfile .NamedTemporaryFile (dir = directory ) as base :
24492452 base_path = base .name
24502453 case_path = base_path .upper ()
@@ -2740,6 +2743,8 @@ def setswitchinterval(interval):
27402743
27412744@contextlib .contextmanager
27422745def disable_faulthandler ():
2746+ import faulthandler
2747+
27432748 # use sys.__stderr__ instead of sys.stderr, since regrtest replaces
27442749 # sys.stderr with a StringIO which has no file descriptor when a test
27452750 # is run with -W/--verbose3.
0 commit comments