Skip to content

Commit

Permalink
increase lock timeout for concurrent tests
Browse files Browse the repository at this point in the history
when running tests in parallel on a weak machine the concurrent test
worker subprocesses will be waiting on the first compilation to finish.
the other tests should not have any contested locks so the extra timeout
is only important for the concurrent tests.
  • Loading branch information
mbway committed Dec 31, 2023
1 parent db520fd commit b79330e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
3 changes: 2 additions & 1 deletion maturin/import_hook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def install(
and so whether the extension module needs to be rebuilt
:param lock_timeout_seconds: a lock is required to prevent projects from being built concurrently.
If the lock is not released before this timeout is reached the import hook stops waiting and aborts
If the lock is not released before this timeout is reached the import hook stops waiting and aborts.
A value of None means that the import hook will wait for the lock indefinitely.
:param show_warnings: whether to show compilation warnings
Expand Down
18 changes: 13 additions & 5 deletions maturin/import_hook/_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,20 @@ def lock(self) -> Generator[LockedBuildCache, None, None]:
@contextmanager
def _acquire_lock(lock: filelock.FileLock) -> Generator[None, None, None]:
try:
with lock.acquire(blocking=False):
yield
try:
with lock.acquire(blocking=False):
yield
except filelock.Timeout:
logger.info("waiting on lock %s", lock.lock_file)
with lock.acquire():
yield
except filelock.Timeout:
logger.info("waiting on lock %s", lock.lock_file)
with lock.acquire():
yield
raise TimeoutError(
f'Acquiring lock "{lock.lock_file}" timed out after {lock.timeout} seconds. '
f"If the project is still compiling and needs more time you can increase the "
f"timeout using the lock_timeout_seconds argument to import_hook.install() "
f"(or set to None to wait indefinitely)"
) from None


def _get_default_build_dir() -> Path:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from maturin import import_hook

import_hook.reset_logger()
import_hook.install()
# increase default timeout as under heavy load on a weak machine
# the workers may be waiting on the locks for a long time.
import_hook.install(lock_timeout_seconds=10 * 60)

import packages.my_rust_module

Expand Down
5 changes: 3 additions & 2 deletions tests/import_hook/test_project_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,9 @@ def test_concurrent_import(workspace: Path, initially_mixed: bool, mixed: bool)

# increase default timeout as under heavy load on a weak machine
# the workers may be waiting on the locks for a long time.
assert "import_hook.install()" in IMPORT_HOOK_HEADER
header = IMPORT_HOOK_HEADER.replace("import_hook.install()", "import_hook.install(lock_timeout_seconds=5 * 60)")
original_call = "import_hook.install()"
assert original_call in IMPORT_HOOK_HEADER
header = IMPORT_HOOK_HEADER.replace(original_call, "import_hook.install(lock_timeout_seconds=10 * 60)")
check_installed_with_hook = f"{header}\n\n{check_installed}"

project_dir = create_project_from_blank_template(project_name, workspace / project_name, mixed=initially_mixed)
Expand Down

0 comments on commit b79330e

Please sign in to comment.