Skip to content

Commit

Permalink
state
Browse files Browse the repository at this point in the history
  • Loading branch information
RonnyPfannschmidt committed Apr 14, 2024
1 parent b931ead commit 42245d3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/execnet/gateway_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ def get_ident(self) -> int:

def sleep(self, delay: float) -> None:
import eventlet
# f = open("/tmp/execnet-%s" % os.getpid(), "w")
# def log_extra(*msg):
# f.write(" ".join([str(x) for x in msg]) + "\n")

eventlet.sleep(delay)

Expand Down
12 changes: 7 additions & 5 deletions src/execnet/gateway_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import inspect
import json
import os

import execnet
Expand All @@ -25,13 +26,13 @@ def bootstrap_import(io: IO, spec: XSpec) -> None:
sendexec(
io,
"import sys",
"if %r not in sys.path:" % importdir,
" sys.path.insert(0, %r)" % importdir,
f"if {importdir!r} not in sys.path:",
f" sys.path.insert(0, {importdir!r})",
"from execnet.gateway_base import serve, init_popen_io, get_execmodel",
"sys.stdout.write('1')",
"sys.stdout.flush()",
"execmodel = get_execmodel(%r)" % spec.execmodel,
"serve(init_popen_io(execmodel), id='%s-worker')" % spec.id,
f"execmodel = get_execmodel({spec.execmodel!r})",
f"serve(init_popen_io(execmodel), id='{spec.id}-worker')",
)
s = io.read(1)
assert s == b"1", repr(s)
Expand Down Expand Up @@ -77,7 +78,8 @@ def bootstrap_socket(io: IO, id) -> None:

def sendexec(io: IO, *sources: str) -> None:
source = "\n".join(sources)
io.write((repr(source) + "\n").encode("utf-8"))
encoded = (json.dumps(source) + "\n").encode("utf-8")
io.write(encoded)


def bootstrap(io: IO, spec: XSpec) -> execnet.Gateway:
Expand Down
2 changes: 1 addition & 1 deletion src/execnet/gateway_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def kill(self) -> None:
sys.stderr.flush()


popen_bootstrapline = "import sys;exec(eval(sys.stdin.readline()))"
popen_bootstrapline = "import sys;import json;exec(json.loads(sys.stdin.readline()))"


def shell_split_path(path: str) -> list[str]:
Expand Down
5 changes: 4 additions & 1 deletion testing/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

import inspect
import json
import os
import subprocess
import sys
Expand Down Expand Up @@ -93,7 +94,9 @@ def receive() -> str:

try:
source = inspect.getsource(read_write_loop) + "read_write_loop()"
send(repr(source) + "\n")
repr_source = json.dumps(source) + "\n"
sendline = repr_source
send(sendline)
s = receive()
assert s == "ok\n"
send("hello\n")
Expand Down

0 comments on commit 42245d3

Please sign in to comment.