Skip to content

Commit 76f15f8

Browse files
committed
async http client for requesting env vars
1 parent 7f9b10f commit 76f15f8

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

template/server/contexts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async def create_context(client, websockets: dict, language: str, cwd: str) -> C
5252
session_data = response.json()
5353
session_id = session_data["id"]
5454
context_id = session_data["kernel"]["id"]
55-
global_env_vars = get_envs()
55+
global_env_vars = await get_envs()
5656

5757
logger.debug(f"Created context {context_id}")
5858

template/server/envs.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import os
22

3-
import requests
3+
import httpx
44

55
LOCAL = os.getenv("E2B_LOCAL", False)
66
ENVD_PORT = 49983
77

88

9-
def get_envs() -> dict:
9+
async def get_envs() -> dict:
1010
if LOCAL:
11-
return {}
12-
return requests.get(f"http://localhost:{ENVD_PORT}/envs").json()
11+
return {
12+
"E2B_TEST_VARIABLE": "true"
13+
}
14+
async with httpx.AsyncClient() as client:
15+
response = await client.get(f"http://localhost:{ENVD_PORT}/envs")
16+
return response.json()

template/server/messaging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ async def set_env_vars(self, env_vars: Dict[StrictStr, str]):
167167
raise ExecutionError(f"Error during execution: {item}")
168168

169169
async def reset_env_vars(self, env_vars: Dict[StrictStr, str]):
170-
global_env_vars = get_envs()
170+
global_env_vars = await get_envs()
171171

172172
# Create a dict of vars to reset and a list of vars to remove
173173
vars_to_reset = {}

0 commit comments

Comments
 (0)