Commit 4ca0ef5c authored by Dmitry Volodin's avatar Dmitry Volodin Committed by Andrey Vertiprahov
Browse files

Optimized run_sync

parent 3a794841
......@@ -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
try:
result.append(await cb())
result = await cb()
except Exception:
error.append(sys.exc_info())
error = sys.exc_info()
if not _setup_completed:
setup_asyncio()
result: List[T] = []
error: List[Tuple[Any, Any, Any]] = []
result: Optional[T] = None
error: Optional[Tuple[Any, Any, Any]] = None
with IOLoopContext() as loop:
loop.run_until_complete(wrapper())
if error:
reraise(*error[0])
return result[0]
reraise(*error)
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