|
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. |
@@ -632,6 +637,8 @@ def update_request(request_id: str) -> Generator[Optional[Request], None, None]: |
632 | 637 | """Get and update a SkyPilot API request.""" |
633 | 638 | # Acquire the lock to avoid race conditions between multiple request |
634 | 639 | # operations, e.g. execute and cancel. |
| 640 | + if not _is_running_pytest() and asyncio_utils.is_running_async(): |
| 641 | + logger.warning('synchronous filelock is being used in an async context') |
635 | 642 | with filelock.FileLock(request_lock_path(request_id)): |
636 | 643 | request = _get_request_no_lock(request_id) |
637 | 644 | yield request |
@@ -718,6 +725,8 @@ async def get_latest_request_id_async() -> Optional[str]: |
718 | 725 | def get_request(request_id: str, |
719 | 726 | fields: Optional[List[str]] = None) -> Optional[Request]: |
720 | 727 | """Get a SkyPilot API request.""" |
| 728 | + if not _is_running_pytest() and asyncio_utils.is_running_async(): |
| 729 | + logger.warning('synchronous filelock is being used in an async context') |
721 | 730 | with filelock.FileLock(request_lock_path(request_id)): |
722 | 731 | return _get_request_no_lock(request_id, fields) |
723 | 732 |
|
|
0 commit comments