Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
135
noc
Commits
a0c88567
Commit
a0c88567
authored
Aug 26, 2020
by
Andrey Vertiprahov
Browse files
Merge branch 'noc-optimize-run_sync' into 'master'
Optimized run_sync See merge request
noc/noc!4210
parents
3b86e5ef
4ca0ef5c
Changes
1
Hide whitespace changes
Inline
Side-by-side
core/ioloop/util.py
View file @
a0c88567
...
...
@@ -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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment