Skip to content

Commit 8d87716

Browse files
committed
Use comments rather than docstrings for internal helpers
1 parent 48734db commit 8d87716

2 files changed

Lines changed: 13 additions & 15 deletions

File tree

‎Lib/importlib/_bootstrap.py‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,18 +1264,17 @@ def _find_and_load_unlocked(name, import_, *, lazy_submodule=False):
12641264
_NEEDS_LOADING = object()
12651265

12661266

1267+
# Return whether module (a sys.modules value) is still executing.
12671268
def _is_initializing(module):
1268-
"""Return whether *module* (a sys.modules value) is still executing."""
12691269
return getattr(getattr(module, '__spec__', None), '_initializing', False)
12701270

12711271

1272+
# Import, or wait for, the parent packages of name.
1273+
#
1274+
# _find_and_load() calls this before taking name's module lock, so that no
1275+
# thread holds a submodule's lock while waiting for its parent. This avoids
1276+
# the deadlocks and import errors of gh-83065 and gh-159963.
12721277
def _resolve_parents(name, import_):
1273-
"""Import, or wait for, the parent packages of *name*.
1274-
1275-
_find_and_load() calls this before taking name's module lock, so that no
1276-
thread holds a submodule's lock while waiting for its parent. This avoids
1277-
the deadlocks and import errors of gh-83065 and gh-159963.
1278-
"""
12791278
# Wait for each ancestor package that another thread is still
12801279
# initializing, outermost first. Importing beneath a package while its
12811280
# __init__ is part way through its own imports could give one of the two

‎Lib/test/test_importlib/test_threaded_import.py‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -531,14 +531,13 @@ def _join_import_threads(self, threads):
531531

532532
def _run_two_first_imports(self, files, stmt1, stmt2, *,
533533
sync_name, t2_waits_for):
534-
"""Thread 1 runs *stmt1*. Something it executes calls
535-
``<sync_name>.hold()``, which starts thread 2 on *stmt2* and returns
536-
only once thread 2 is blocked on the module lock of *t2_waits_for*
537-
(any module lock if None). Module code may also call
538-
``<sync_name>.join_t2()`` to wait for thread 2 to finish.
539-
Returns a list of (what, problem) pairs; empty means both imports
540-
succeeded and no module body ran more than once.
541-
"""
534+
# Thread 1 runs stmt1. Something it executes calls
535+
# <sync_name>.hold(), which starts thread 2 on stmt2 and returns
536+
# only once thread 2 is blocked on the module lock of t2_waits_for
537+
# (any module lock if None). Module code may also call
538+
# <sync_name>.join_t2() to wait for thread 2 to finish.
539+
# Returns a list of (what, problem) pairs; empty means both imports
540+
# succeeded and no module body ran more than once.
542541
# list.append() is atomic, on free-threaded builds too.
543542
count = f"import {sync_name}; {sync_name}.executed.append(__name__)\n"
544543
self._setup_package_tree({relpath: count + source

0 commit comments

Comments
 (0)