stores 0.1.7.dev1__py3-none-any.whl → 0.1.7.dev2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- stores/indexes/venv_utils.py +41 -17
- {stores-0.1.7.dev1.dist-info → stores-0.1.7.dev2.dist-info}/METADATA +1 -1
- {stores-0.1.7.dev1.dist-info → stores-0.1.7.dev2.dist-info}/RECORD +5 -5
- {stores-0.1.7.dev1.dist-info → stores-0.1.7.dev2.dist-info}/WHEEL +0 -0
- {stores-0.1.7.dev1.dist-info → stores-0.1.7.dev2.dist-info}/licenses/LICENSE +0 -0
stores/indexes/venv_utils.py
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import asyncio
|
1
2
|
import hashlib
|
2
3
|
import inspect
|
3
4
|
import json
|
@@ -308,7 +309,7 @@ def parse_tool_signature(
|
|
308
309
|
|
309
310
|
async def func_handler(*args, **kwargs):
|
310
311
|
# TODO: Make this truly async
|
311
|
-
for value in run_remote_tool(
|
312
|
+
async for value in run_remote_tool(
|
312
313
|
tool_id=signature_dict["tool_id"],
|
313
314
|
index_folder=index_folder,
|
314
315
|
args=args,
|
@@ -410,7 +411,7 @@ def run_remote_tool(
|
|
410
411
|
|
411
412
|
result_data = {}
|
412
413
|
|
413
|
-
def
|
414
|
+
def handle_connection_sync():
|
414
415
|
conn, _ = listener.accept()
|
415
416
|
with conn:
|
416
417
|
buffer = ""
|
@@ -425,24 +426,43 @@ def run_remote_tool(
|
|
425
426
|
continue
|
426
427
|
msg = json.loads(line)
|
427
428
|
if msg.get("ok") and "stream" in msg:
|
428
|
-
|
429
|
-
yield msg["stream"]
|
430
|
-
else:
|
431
|
-
result_data.setdefault("stream", []).append(msg["stream"])
|
429
|
+
result_data.setdefault("stream", []).append(msg["stream"])
|
432
430
|
elif msg.get("ok") and "result" in msg:
|
433
431
|
result_data["result"] = msg["result"]
|
434
432
|
elif "error" in msg:
|
435
433
|
result_data["error"] = msg["error"]
|
436
434
|
elif msg.get("done"):
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
435
|
+
return
|
436
|
+
|
437
|
+
async def handle_connection_async():
|
438
|
+
loop = asyncio.get_running_loop()
|
439
|
+
conn, _ = await loop.sock_accept(listener)
|
440
|
+
conn.setblocking(False)
|
441
|
+
buffer = ""
|
442
|
+
try:
|
443
|
+
while True:
|
444
|
+
chunk = await loop.sock_recv(conn, 4096)
|
445
|
+
if not chunk:
|
446
|
+
break
|
447
|
+
buffer += chunk.decode("utf-8")
|
448
|
+
while "\n" in buffer:
|
449
|
+
line, buffer = buffer.split("\n", 1)
|
450
|
+
if not line.strip():
|
451
|
+
continue
|
452
|
+
msg = json.loads(line)
|
453
|
+
if msg.get("ok") and "stream" in msg:
|
454
|
+
yield msg["stream"]
|
455
|
+
elif msg.get("ok") and "result" in msg:
|
456
|
+
yield msg["result"]
|
457
|
+
elif "error" in msg:
|
458
|
+
raise RuntimeError(f"Subprocess error:\n{msg['error']}")
|
459
|
+
elif msg.get("done"):
|
460
|
+
return
|
461
|
+
finally:
|
462
|
+
conn.close()
|
441
463
|
|
442
464
|
if not stream:
|
443
|
-
thread = threading.Thread(
|
444
|
-
target=lambda: list(handle_connection(stream_mode=False))
|
445
|
-
)
|
465
|
+
thread = threading.Thread(target=lambda: list(handle_connection_sync()))
|
446
466
|
thread.start()
|
447
467
|
|
448
468
|
runner = f"""
|
@@ -493,12 +513,16 @@ finally:
|
|
493
513
|
except:
|
494
514
|
pass
|
495
515
|
"""
|
496
|
-
|
516
|
+
|
517
|
+
proc = subprocess.Popen(
|
497
518
|
[get_python_command(Path(index_folder) / venv), "-c", runner],
|
498
|
-
|
499
|
-
|
519
|
+
stdin=subprocess.PIPE,
|
520
|
+
stdout=subprocess.DEVNULL,
|
521
|
+
stderr=subprocess.PIPE,
|
500
522
|
env=env_var or None,
|
501
523
|
)
|
524
|
+
proc.stdin.write(payload)
|
525
|
+
proc.stdin.close()
|
502
526
|
|
503
527
|
if not stream:
|
504
528
|
thread.join()
|
@@ -512,4 +536,4 @@ finally:
|
|
512
536
|
else:
|
513
537
|
raise RuntimeError("Subprocess completed without returning data.")
|
514
538
|
else:
|
515
|
-
return
|
539
|
+
return handle_connection_async()
|
@@ -8,8 +8,8 @@ stores/indexes/base_index.py,sha256=YrEwETZ5eXj3rXK5qxOllRXqFifQoteYdzPAasbvEyg,
|
|
8
8
|
stores/indexes/index.py,sha256=Cub5mtnYGipHfPR8BexJYRSKfuJmcGPp0B3ou2bGNqs,2901
|
9
9
|
stores/indexes/local_index.py,sha256=Gg9LkEo1L0_NZZYPItsF_-1y6nFP369C3QlPvPyvPx8,3708
|
10
10
|
stores/indexes/remote_index.py,sha256=-GV4l2c7GL6_bcVOQnSK5rzYru237bwC5L6eiO-QFzM,3438
|
11
|
-
stores/indexes/venv_utils.py,sha256=
|
12
|
-
stores-0.1.7.
|
13
|
-
stores-0.1.7.
|
14
|
-
stores-0.1.7.
|
15
|
-
stores-0.1.7.
|
11
|
+
stores/indexes/venv_utils.py,sha256=tS2ZYt2Cf7rqHxBXwn5EoEdUFjyaAIXVRiy8iXjCMb4,17397
|
12
|
+
stores-0.1.7.dev2.dist-info/METADATA,sha256=AciMTIC_8qRvud2y3guHn78X-F_n5j-rlCOUNeFLBAc,3081
|
13
|
+
stores-0.1.7.dev2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
14
|
+
stores-0.1.7.dev2.dist-info/licenses/LICENSE,sha256=VTidYE7_Dam0Dwyq095EhhDIqi47g03oVpLAHQgKws0,1066
|
15
|
+
stores-0.1.7.dev2.dist-info/RECORD,,
|
File without changes
|
File without changes
|