Skip to content

Commit afa68b5

Browse files
committed
sync codepath detector
1 parent a2f0669 commit afa68b5

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

sky/jobs/server/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ async def pool_tail_logs(
206206
request_cluster_name=common.JOB_CONTROLLER_NAME,
207207
)
208208

209-
request_task = api_requests.get_request(request.state.request_id,
210-
fields=['request_id'])
209+
request_task = await api_requests.get_request_async(
210+
request.state.request_id, fields=['request_id'])
211211

212212
return stream_utils.stream_response_for_long_request(
213213
request_id=request_task.request_id,

sky/server/requests/requests.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@
5151

5252
DEFAULT_REQUESTS_RETENTION_HOURS = 24 # 1 day
5353

54+
55+
def _is_running_pytest() -> bool:
56+
return 'PYTEST_CURRENT_TEST' in os.environ
57+
58+
5459
# TODO(zhwu): For scalability, there are several TODOs:
5560
# [x] Have a way to queue requests.
5661
# [ ] Move logs to persistent place.
@@ -632,6 +637,8 @@ def update_request(request_id: str) -> Generator[Optional[Request], None, None]:
632637
"""Get and update a SkyPilot API request."""
633638
# Acquire the lock to avoid race conditions between multiple request
634639
# 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')
635642
with filelock.FileLock(request_lock_path(request_id)):
636643
request = _get_request_no_lock(request_id)
637644
yield request
@@ -718,6 +725,8 @@ async def get_latest_request_id_async() -> Optional[str]:
718725
def get_request(request_id: str,
719726
fields: Optional[List[str]] = None) -> Optional[Request]:
720727
"""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')
721730
with filelock.FileLock(request_lock_path(request_id)):
722731
return _get_request_no_lock(request_id, fields)
723732

sky/utils/asyncio_utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,12 @@ async def async_wrapper(*args, **kwargs):
7676
raise
7777

7878
return async_wrapper
79+
80+
81+
def is_running_async() -> bool:
82+
"""Check if the code is currently running inside an asyncio event loop."""
83+
try:
84+
asyncio.get_running_loop()
85+
return True
86+
except RuntimeError:
87+
return False

0 commit comments

Comments
 (0)