Skip to content

Commit 4f2c8e3

Browse files
vzhestkovdwoz
authored andcommitted
Run method with distinct thread only if io_loop is already running
1 parent d96944d commit 4f2c8e3

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

salt/utils/asynchronous.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ def __getattr__(self, key):
125125

126126
def _wrap(self, key):
127127
def wrap(*args, **kwargs):
128+
try:
129+
asyncio.get_running_loop()
130+
except RuntimeError:
131+
# asyncio.get_running_loop() raises RuntimeError
132+
# if there is no running loop, so we can run the method
133+
# directly with no detaching it to the distinct thread.
134+
# It will make SyncWrapper way faster for the cases
135+
# when there are no nested SyncWrapper objects used.
136+
return self.io_loop.run_sync(
137+
lambda: getattr(self.obj, key)(*args, **kwargs)
138+
)
128139
results = []
129140
thread = threading.Thread(
130141
target=self._target,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy