Skip to content

Commit e049178

Browse files
committed
trigger async actions in loops
1 parent c3a2cc2 commit e049178

File tree

6 files changed

+16
-12
lines changed

6 files changed

+16
-12
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_signal.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,8 @@ def handler(signal, frame):
5656

5757
_signal.alarm(1)
5858

59-
def dummy():
60-
pass
61-
6259
while not triggered:
63-
dummy()
6460
time.sleep(0.5)
6561

6662
assert triggered[0] == _signal.SIGALRM
67-
assert triggered[1].f_code.co_name == "test_alarm2", triggered[1].f_code.co_name
63+
assert triggered[1].f_code.co_name == "test_alarm2", triggered[1].f_code

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/control/ForNode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2019, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -71,6 +71,7 @@ public boolean executeRepeating(VirtualFrame frame) {
7171
throw raise(PythonErrorType.RuntimeError, "internal error: unexpected frame slot type");
7272
}
7373
body.executeVoid(frame);
74+
getContext().triggerAsyncActions();
7475
return true;
7576
}
7677
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/control/WhileNode.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2019, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -25,16 +25,16 @@
2525
*/
2626
package com.oracle.graal.python.nodes.control;
2727

28+
import com.oracle.graal.python.nodes.PNodeWithContext;
2829
import com.oracle.graal.python.nodes.expression.CastToBooleanNode;
2930
import com.oracle.graal.python.nodes.statement.StatementNode;
3031
import com.oracle.truffle.api.Truffle;
3132
import com.oracle.truffle.api.frame.VirtualFrame;
32-
import com.oracle.truffle.api.nodes.Node;
3333
import com.oracle.truffle.api.nodes.NodeInfo;
3434
import com.oracle.truffle.api.nodes.RepeatingNode;
3535
import com.oracle.truffle.api.profiles.LoopConditionProfile;
3636

37-
final class WhileRepeatingNode extends Node implements RepeatingNode {
37+
final class WhileRepeatingNode extends PNodeWithContext implements RepeatingNode {
3838

3939
private final LoopConditionProfile conditionProfile = LoopConditionProfile.createCountingProfile();
4040

@@ -50,6 +50,7 @@ final class WhileRepeatingNode extends Node implements RepeatingNode {
5050
public boolean executeRepeating(VirtualFrame frame) {
5151
if (conditionProfile.profile(condition.executeBoolean(frame))) {
5252
body.executeVoid(frame);
53+
getContext().triggerAsyncActions();
5354
return true;
5455
}
5556
return false;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/generator/GeneratorForNode.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2019, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -31,6 +31,7 @@
3131
import com.oracle.graal.python.nodes.frame.WriteNode;
3232
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
3333
import com.oracle.graal.python.nodes.statement.StatementNode;
34+
import com.oracle.graal.python.runtime.PythonContext;
3435
import com.oracle.graal.python.runtime.exception.PException;
3536
import com.oracle.graal.python.runtime.exception.YieldException;
3637
import com.oracle.truffle.api.CompilerDirectives;
@@ -93,6 +94,7 @@ public void executeVoid(VirtualFrame frame) {
9394
}
9495

9596
Object nextIterator = null;
97+
PythonContext context = getContext();
9698
int count = 0;
9799
try {
98100
while (true) {
@@ -108,6 +110,7 @@ public void executeVoid(VirtualFrame frame) {
108110
if (CompilerDirectives.inInterpreter()) {
109111
count++;
110112
}
113+
context.triggerAsyncActions();
111114
}
112115
return;
113116
} catch (YieldException e) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/generator/GeneratorWhileNode.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2019, Oracle and/or its affiliates.
33
* Copyright (c) 2014, Regents of the University of California
44
*
55
* All rights reserved.
@@ -28,6 +28,7 @@
2828
import com.oracle.graal.python.nodes.control.LoopNode;
2929
import com.oracle.graal.python.nodes.expression.CastToBooleanNode;
3030
import com.oracle.graal.python.nodes.statement.StatementNode;
31+
import com.oracle.graal.python.runtime.PythonContext;
3132
import com.oracle.graal.python.runtime.exception.BreakException;
3233
import com.oracle.graal.python.runtime.exception.YieldException;
3334
import com.oracle.truffle.api.CompilerDirectives;
@@ -68,12 +69,14 @@ public void executeVoid(VirtualFrame frame) {
6869
}
6970
boolean nextFlag = false;
7071
int count = 0;
72+
PythonContext context = getContext();
7173
try {
7274
do {
7375
body.executeVoid(frame);
7476
if (CompilerDirectives.inInterpreter()) {
7577
count++;
7678
}
79+
context.triggerAsyncActions();
7780
} while (condition.executeBoolean(frame));
7881
return;
7982
} catch (YieldException e) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public Object execute(VirtualFrame frame) {
126126
int frameIndex = (int) frameArguments[1];
127127
Object[] arguments = Arrays.copyOfRange(frameArguments, 2, frameArguments.length);
128128
if (frameIndex >= 0) {
129-
arguments[frameIndex] = getFrameNode.execute(2);
129+
arguments[frameIndex] = getFrameNode.execute(1);
130130
}
131131
return callNode.execute(frame, callable, arguments);
132132
}

0 commit comments

Comments
 (0)