Commit a0c88567 authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

Merge branch 'noc-optimize-run_sync' into 'master'

Optimized run_sync

See merge request noc/noc!4210
parents 3b86e5ef 4ca0ef5c
......@@ -11,7 +11,7 @@ import asyncio
import logging
# Third-party modules
from typing import Callable, TypeVar, List, Tuple, Any, Optional
from typing import Callable, TypeVar, Tuple, Any, Optional
# NOC modules
from noc.config import config
......@@ -87,22 +87,23 @@ def run_sync(cb: Callable[..., T], close_all: bool = True) -> T:
global _setup_completed
async def wrapper():
nonlocal result, error
result.append(await cb())
result = await cb()
except Exception:
error = sys.exc_info()
if not _setup_completed:
result: List[T] = []
error: List[Tuple[Any, Any, Any]] = []
result: Optional[T] = None
error: Optional[Tuple[Any, Any, Any]] = None
with IOLoopContext() as loop:
if error:
return result[0]
return result
_setup_completed = False
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment