Skip to content

Commit 1bcb621

Browse files
committed
Fixing deadlock in multi threading context.
1 parent 10b1667 commit 1bcb621

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ public long spawnTruffleContext(PythonContext context, int fd, int sentinel, int
787787
}
788788

789789
Builder builder = data.parentCtx.env.newContextBuilder().config(PythonContext.CHILD_CONTEXT_DATA, data);
790-
Thread thread = data.parentCtx.env.createThread(new ChildContextThread(context, fd, sentinel, data, builder));
790+
Thread thread = data.parentCtx.env.createThread(new ChildContextThread(fd, sentinel, data, builder));
791791

792792
// TODO always force java posix in spawned
793793
long tid = thread.getId();
@@ -819,30 +819,28 @@ private static class ChildContextThread implements Runnable {
819819
private final ChildContextData data;
820820
private final Builder builder;
821821
private final int sentinel;
822-
private final PythonContext context;
823822

824-
public ChildContextThread(PythonContext context, int fd, int sentinel, ChildContextData data, Builder builder) {
823+
public ChildContextThread(int fd, int sentinel, ChildContextData data, Builder builder) {
825824
this.fd = fd;
826825
this.data = data;
827826
this.builder = builder;
828827
this.sentinel = sentinel;
829-
this.context = context;
830828
}
831829

832830
@Override
833831
public void run() {
834832
try {
835833
LOGGER.fine("starting spawned child context");
834+
Source source = Source.newBuilder(PythonLanguage.ID,
835+
"from multiprocessing.spawn import spawn_truffleprocess; spawn_truffleprocess(" + fd + ", " + sentinel + ")",
836+
"<spawned-child-context>").internal(true).build();
837+
CallTarget ct;
838+
ct = data.parentCtx.getEnv().parsePublic(source);
836839
TruffleContext ctx = builder.build();
837840
data.setTruffleContext(ctx);
838841
Object parent = ctx.enter(null);
839842
try {
840-
Source source = Source.newBuilder(PythonLanguage.ID,
841-
"from multiprocessing.spawn import spawn_truffleprocess; spawn_truffleprocess(" + fd + ", " + sentinel + ")",
842-
"<spawned-child-context>").internal(true).build();
843-
CallTarget ct = context.getEnv().parsePublic(source);
844843
data.running.countDown();
845-
846844
Object res = ct.call();
847845
int exitCode = CastToJavaIntLossyNode.getUncached().execute(res);
848846
data.setExitCode(exitCode);

0 commit comments

Comments
 (0)