|
51 | 51 |
|
52 | 52 | DEFAULT_REQUESTS_RETENTION_HOURS = 24 # 1 day |
53 | 53 |
|
| 54 | + |
| 55 | +def _is_running_pytest() -> bool: |
| 56 | + return 'PYTEST_CURRENT_TEST' in os.environ |
| 57 | + |
| 58 | + |
54 | 59 | # TODO(zhwu): For scalability, there are several TODOs: |
55 | 60 | # [x] Have a way to queue requests. |
56 | 61 | # [ ] Move logs to persistent place. |
@@ -666,6 +671,8 @@ def update_request(request_id: str) -> Generator[Optional[Request], None, None]: |
666 | 671 | """Get and update a SkyPilot API request.""" |
667 | 672 | # Acquire the lock to avoid race conditions between multiple request |
668 | 673 | # operations, e.g. execute and cancel. |
| 674 | + if not _is_running_pytest() and asyncio_utils.is_running_async(): |
| 675 | + logger.warning('synchronous filelock is being used in an async context') |
669 | 676 | with filelock.FileLock(request_lock_path(request_id)): |
670 | 677 | request = _get_request_no_lock(request_id) |
671 | 678 | yield request |
@@ -752,6 +759,8 @@ async def get_latest_request_id_async() -> Optional[str]: |
752 | 759 | def get_request(request_id: str, |
753 | 760 | fields: Optional[List[str]] = None) -> Optional[Request]: |
754 | 761 | """Get a SkyPilot API request.""" |
| 762 | + if not _is_running_pytest() and asyncio_utils.is_running_async(): |
| 763 | + logger.warning('synchronous filelock is being used in an async context') |
755 | 764 | with filelock.FileLock(request_lock_path(request_id)): |
756 | 765 | return _get_request_no_lock(request_id, fields) |
757 | 766 |
|
|
0 commit comments