Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

timeout: Remove unnecessary varargs support.

Anders Kaseorgb728727d9da6
diff --git a/zerver/lib/markdown/__init__.py b/zerver/lib/markdown/__init__.py
index 3d49db738cd..c5f39eb2238 100644
--- a/zerver/lib/markdown/__init__.py
+++ b/zerver/lib/markdown/__init__.py
@@ -420,7 +420,7 @@ def fetch_tweet_data(tweet_id: str) -> Optional[Dict[str, Any]]:
# preview, rather than having the message be rejected
# entirely. This timeout needs to be less than our overall
# formatting timeout.
- tweet = timeout(3, api.GetStatus, tweet_id)
+ tweet = timeout(3, lambda: api.GetStatus(tweet_id))
res = tweet.AsDict()
except TimeoutExpired:
# We'd like to try again later and not cache the bad result,
@@ -2541,7 +2541,7 @@ def do_convert(
# extremely inefficient in corner cases) as well as user
# errors (e.g. a realm filter that makes some syntax
# infinite-loop).
- rendered_content = timeout(5, _md_engine.convert, content)
+ rendered_content = timeout(5, lambda: _md_engine.convert(content))
# Throw an exception if the content is huge; this protects the
# rest of the codebase from any bugs where we end up rendering
diff --git a/zerver/lib/timeout.py b/zerver/lib/timeout.py
index 7b5c1213f41..180d9fc7830 100644
--- a/zerver/lib/timeout.py
+++ b/zerver/lib/timeout.py
@@ -3,7 +3,7 @@ import sys
import threading
import time
from types import TracebackType
-from typing import Any, Callable, Optional, Tuple, Type, TypeVar
+from typing import Callable, Optional, Tuple, Type, TypeVar
# Based on https://code.activestate.com/recipes/483752/
@@ -18,7 +18,7 @@ class TimeoutExpired(Exception):
ResultT = TypeVar("ResultT")
-def timeout(timeout: float, func: Callable[..., ResultT], *args: Any, **kwargs: Any) -> ResultT:
+def timeout(timeout: float, func: Callable[[], ResultT]) -> ResultT:
"""Call the function in a separate thread.
Return its return value, or raise an exception,
within approximately 'timeout' seconds.
@@ -50,7 +50,7 @@ def timeout(timeout: float, func: Callable[..., ResultT], *args: Any, **kwargs:
def run(self) -> None:
try:
- self.result = func(*args, **kwargs)
+ self.result = func()
except BaseException:
self.exc_info = sys.exc_info()