Skip to content

Commit 259a81b

Browse files
authored
Fix timeouts (#234)
1 parent 520de17 commit 259a81b

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

ragna/_utils.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import functools
2+
import inspect
23
import os
4+
import sys
35
import threading
46
from pathlib import Path
57
from typing import Any, Callable, Optional, Union
@@ -72,12 +74,15 @@ def handle_localhost_origins(origins: list[str]) -> list[str]:
7274

7375

7476
def timeout_after(
75-
seconds: float = 5, *, message: str = ""
77+
seconds: float = 30, *, message: str = ""
7678
) -> Callable[[Callable], Callable]:
7779
timeout = f"Timeout after {seconds:.1f} seconds"
7880
message = timeout if message else f"{timeout}: {message}"
7981

8082
def decorator(fn: Callable) -> Callable:
83+
if is_debugging():
84+
return fn
85+
8186
@functools.wraps(fn)
8287
def wrapper(*args: Any, **kwargs: Any) -> Any:
8388
result: Any = TimeoutError(message)
@@ -103,3 +108,20 @@ def target() -> None:
103108
return wrapper
104109

105110
return decorator
111+
112+
113+
# Vendored from pytest-timeout
114+
# https://github.com/pytest-dev/pytest-timeout/blob/d91e6d8d69ad706e38a2c9de461a72c4d19777ff/pytest_timeout.py#L218-L247
115+
def is_debugging() -> bool:
116+
trace_func = sys.gettrace()
117+
trace_module = None
118+
if trace_func:
119+
trace_module = inspect.getmodule(trace_func) or inspect.getmodule(
120+
trace_func.__class__
121+
)
122+
if trace_module:
123+
parts = trace_module.__name__.split(".")
124+
for name in {"pydevd", "bdb", "pydevd_frame_evaluator"}:
125+
if any(part.startswith(name) for part in parts):
126+
return True
127+
return False

ragna/deploy/_cli/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def check_api_available() -> bool:
131131
try:
132132
if process is not None:
133133

134-
@timeout_after(30)
134+
@timeout_after()
135135
def wait_for_api() -> None:
136136
while not check_api_available():
137137
time.sleep(0.5)

tests/utils.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import contextlib
2-
import inspect
32
import socket
43
import subprocess
54
import sys
@@ -20,23 +19,6 @@ def background_subprocess(*args, stdout=sys.stdout, stderr=sys.stdout, **kwargs)
2019
process.communicate()
2120

2221

23-
# Vendored from pytest-timeout
24-
# https://github.com/pytest-dev/pytest-timeout/blob/d91e6d8d69ad706e38a2c9de461a72c4d19777ff/pytest_timeout.py#L218-L247
25-
def is_debugging():
26-
trace_func = sys.gettrace()
27-
trace_module = None
28-
if trace_func:
29-
trace_module = inspect.getmodule(trace_func) or inspect.getmodule(
30-
trace_func.__class__
31-
)
32-
if trace_module:
33-
parts = trace_module.__name__.split(".")
34-
for name in {"pydevd", "bdb", "pydevd_frame_evaluator"}:
35-
if any(part.startswith(name) for part in parts):
36-
return True
37-
return False
38-
39-
4022
def get_available_port():
4123
with socket.socket() as s:
4224
s.bind(("", 0))

0 commit comments

Comments
 (0)