Skip to content

Commit 7e86f6e

Browse files
state
1 parent 4c7afbf commit 7e86f6e

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,4 @@ include = [
6969

7070
[tool.mypy]
7171
python_version = "3.8"
72+
mypy_path = "$MYPY_CONFIG_FILE_DIR/src"

src/execnet/gateway_base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ def get_ident(self):
166166

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

170173
eventlet.sleep(delay)
171174

src/execnet/gateway_bootstrap.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
code to initialize the remote side of a gateway once the io is created
33
"""
44
import inspect
5+
import json
56
import os
67

78
import execnet
@@ -23,13 +24,13 @@ def bootstrap_import(io, spec):
2324
sendexec(
2425
io,
2526
"import sys",
26-
"if %r not in sys.path:" % importdir,
27-
" sys.path.insert(0, %r)" % importdir,
27+
f"if {importdir!r} not in sys.path:",
28+
f" sys.path.insert(0, {importdir!r})",
2829
"from execnet.gateway_base import serve, init_popen_io, get_execmodel",
2930
"sys.stdout.write('1')",
3031
"sys.stdout.flush()",
31-
"execmodel = get_execmodel(%r)" % spec.execmodel,
32-
"serve(init_popen_io(execmodel), id='%s-worker')" % spec.id,
32+
f"execmodel = get_execmodel({spec.execmodel!r})",
33+
f"serve(init_popen_io(execmodel), id='{spec.id}-worker')",
3334
)
3435
s = io.read(1)
3536
assert s == b"1", repr(s)
@@ -75,7 +76,8 @@ def bootstrap_socket(io, id):
7576

7677
def sendexec(io, *sources):
7778
source = "\n".join(sources)
78-
io.write((repr(source) + "\n").encode("utf-8"))
79+
encoded = (json.dumps(source) + "\n").encode("utf-8")
80+
io.write(encoded)
7981

8082

8183
def bootstrap(io, spec):

src/execnet/gateway_io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def killpopen(popen):
4040
sys.stderr.flush()
4141

4242

43-
popen_bootstrapline = "import sys;exec(eval(sys.stdin.readline()))"
43+
popen_bootstrapline = "import sys;import json;exec(json.loads(sys.stdin.readline()))"
4444

4545

4646
def shell_split_path(path):

testing/test_basics.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import inspect
4+
import json
45
import os
56
import subprocess
67
import sys
@@ -85,7 +86,9 @@ def receive():
8586

8687
try:
8788
source = inspect.getsource(read_write_loop) + "read_write_loop()"
88-
send(repr(source) + "\n")
89+
repr_source = json.dumps(source) + "\n"
90+
sendline = repr_source
91+
send(sendline)
8992
s = receive()
9093
assert s == "ok\n"
9194
send("hello\n")

0 commit comments

Comments
 (0)