FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sdk-python/src/strands/_async.py at main · polytech-dev/sdk-python · GitHub
polytech-dev
/
sdk-python
Public
forked from
strands-agents/harness-sdk
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
sdk-python
/
src
/
strands
/
_async.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
33 lines (23 loc) · 931 Bytes
Breadcrumbs
sdk-python
/
src
/
strands
/
_async.py
Copy path
File metadata and controls
33 lines (23 loc) · 931 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""Private async execution utilities."""
import
asyncio
import
contextvars
from
concurrent
.
futures
import
ThreadPoolExecutor
from
typing
import
Awaitable
,
Callable
,
TypeVar
T
=
TypeVar
(
"T"
)
def
run_async
(
async_func
:
Callable
[[],
Awaitable
[
T
]])
->
T
:
"""Run an async function in a separate thread to avoid event loop conflicts.
This utility handles the common pattern of running async code from sync contexts
by using ThreadPoolExecutor to isolate the async execution.
Args:
async_func: A callable that returns an awaitable
Returns:
The result of the async function
"""
async
def
execute_async
()
->
T
:
return
await
async_func
()
def
execute
()
->
T
:
return
asyncio
.
run
(
execute_async
())
with
ThreadPoolExecutor
()
as
executor
:
context
=
contextvars
.
copy_context
()
future
=
executor
.
submit
(
context
.
run
,
execute
)
return
future
.
result
()
Back
|
FazBrowse Home
|
New Git URL