gemini-code-assist[bot] commented on code in PR #654: URL: https://github.com/apache/tvm-ffi/pull/654#discussion_r3524157996
########## python/tvm_ffi/testing/_locking.py: ########## @@ -0,0 +1,100 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""Helpers for tests that use exclusive machine-local resources. + +Parallel test runners (for example ``pytest -n auto``) spread tests across +several worker processes. Tests that reach for a shared, machine-local +resource such as a single GPU must serialize with each other so that +concurrent access does not exhaust device memory or corrupt device state. +:func:`run_with_gpu_lock` provides that serialization through an advisory +file lock shared by every cooperating worker on the machine. +""" + +from __future__ import annotations + +import os +import tempfile +from collections.abc import Callable +from pathlib import Path +from typing import Any, TypeVar + +from ..utils import FileLock + +_LOCK_DIR_ENV_VAR = "TVM_FFI_TEST_LOCK_DIR" +_LOCK_DIR_NAME = "tvm-ffi-testing-locks" Review Comment:  On shared development servers or multi-user CI/CD environments, using a static, predictable directory name like `tvm-ffi-testing-locks` under the system temporary directory (`/tmp` on Unix) can lead to `PermissionError` or flaky test runs. The first user who runs the tests will create the directory with their own ownership and restrictive permissions (due to default umask). When a second user subsequently runs the tests, they will be unable to write to or create the lock file inside that directory, causing the test suite to fail. To prevent this, we should make the default lock directory user-specific by appending the current username (retrieved safely via `getpass.getuser()`). ```python import getpass import os import tempfile from collections.abc import Callable from pathlib import Path from typing import Any, TypeVar from ..utils import FileLock _LOCK_DIR_ENV_VAR = "TVM_FFI_TEST_LOCK_DIR" try: _username = getpass.getuser() except Exception: _username = "unknown" _LOCK_DIR_NAME = f"tvm-ffi-testing-locks-{_username}" ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
