|
84 | 84 | import static com.oracle.graal.python.nodes.ErrorMessages.ARG_TYPE_MUST_BE;
|
85 | 85 | import static com.oracle.graal.python.nodes.ErrorMessages.LOST_S;
|
86 | 86 | import static com.oracle.graal.python.nodes.ErrorMessages.REC_LIMIT_GREATER_THAN_1;
|
| 87 | +import static com.oracle.graal.python.nodes.ErrorMessages.SWITCH_INTERVAL_MUST_BE_POSITIVE; |
87 | 88 | import static com.oracle.graal.python.nodes.ErrorMessages.S_EXPECTED_GOT_P;
|
88 | 89 | import static com.oracle.graal.python.nodes.ErrorMessages.WARN_CANNOT_RUN_PDB_YET;
|
89 | 90 | import static com.oracle.graal.python.nodes.ErrorMessages.WARN_DEPRECTATED_SYS_CHECKINTERVAL;
|
|
103 | 104 | import java.util.Map;
|
104 | 105 | import java.util.Set;
|
105 | 106 |
|
| 107 | +import com.oracle.graal.python.lib.PyFloatAsDoubleNode; |
106 | 108 | import com.oracle.graal.python.lib.PyFloatCheckExactNode;
|
107 | 109 | import com.oracle.graal.python.lib.PyLongAsIntNode;
|
108 | 110 | import org.graalvm.nativeimage.ImageInfo;
|
@@ -1483,4 +1485,50 @@ Object setCheckInterval(VirtualFrame frame, @SuppressWarnings("unused") PythonMo
|
1483 | 1485 | return PNone.NONE;
|
1484 | 1486 | }
|
1485 | 1487 | }
|
| 1488 | + |
| 1489 | + @Builtin(name = "getswitchinterval", minNumOfPositionalArgs = 1, declaresExplicitSelf = true, doc = "getswitchinterval($module, /)\n" + |
| 1490 | + "--\n" + |
| 1491 | + "\n" + |
| 1492 | + "Return the current thread switch interval; see sys.setswitchinterval().") |
| 1493 | + @GenerateNodeFactory |
| 1494 | + abstract static class GetSwitchIntervalNode extends PythonBuiltinNode { |
| 1495 | + private final static double FACTOR = 1.e-6; |
| 1496 | + |
| 1497 | + @Specialization |
| 1498 | + Object getCheckInterval(VirtualFrame frame, @SuppressWarnings("unused") PythonModule sys) { |
| 1499 | + return FACTOR * getContext().getSysModuleState().getSwitchInterval(); |
| 1500 | + } |
| 1501 | + } |
| 1502 | + |
| 1503 | + @Builtin(name = "setswitchinterval", minNumOfPositionalArgs = 2, declaresExplicitSelf = true, doc = "setswitchinterval($module, interval, /)\n" + |
| 1504 | + "--\n" + |
| 1505 | + "\n" + |
| 1506 | + "Set the ideal thread switching delay inside the Python interpreter.\n" + |
| 1507 | + "\n" + |
| 1508 | + "The actual frequency of switching threads can be lower if the\n" + |
| 1509 | + "interpreter executes long sequences of uninterruptible code" + |
| 1510 | + "(this is implementation-specific and workload-dependent).\n" + |
| 1511 | + "\n" + |
| 1512 | + "The parameter must represent the desired switching delay in seconds\n" + |
| 1513 | + "A typical value is 0.005 (5 milliseconds).") |
| 1514 | + @GenerateNodeFactory |
| 1515 | + abstract static class SetSwitchIntervalNode extends PythonBuiltinNode { |
| 1516 | + private final static double FACTOR = 1.e6; |
| 1517 | + |
| 1518 | + @Specialization |
| 1519 | + Object setCheckInterval(VirtualFrame frame, @SuppressWarnings("unused") PythonModule sys, Object arg, |
| 1520 | + @Cached PyFloatAsDoubleNode floatAsDoubleNode, |
| 1521 | + @Cached PyFloatCheckExactNode floatCheckExactNode) { |
| 1522 | + try { |
| 1523 | + double interval = floatAsDoubleNode.execute(frame, arg); |
| 1524 | + if (interval <= 0.0) { |
| 1525 | + throw raise(ValueError, SWITCH_INTERVAL_MUST_BE_POSITIVE); |
| 1526 | + } |
| 1527 | + getContext().getSysModuleState().setSwitchInterval(FACTOR * interval); |
| 1528 | + } catch (PException ignore) { |
| 1529 | + |
| 1530 | + } |
| 1531 | + return PNone.NONE; |
| 1532 | + } |
| 1533 | + } |
1486 | 1534 | }
|
0 commit comments