|
41 | 41 | package com.oracle.graal.python.builtins.modules;
|
42 | 42 |
|
43 | 43 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.AttributeError;
|
| 44 | +import static com.oracle.graal.python.builtins.PythonBuiltinClassType.DeprecationWarning; |
44 | 45 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ImportError;
|
45 | 46 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.RuntimeError;
|
46 | 47 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.RuntimeWarning;
|
47 |
| -import static com.oracle.graal.python.builtins.PythonBuiltinClassType.SystemExit; |
48 | 48 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError;
|
49 | 49 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.UnicodeEncodeError;
|
50 | 50 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ValueError;
|
|
69 | 69 | import static com.oracle.graal.python.nodes.BuiltinNames.BUILTINS;
|
70 | 70 | import static com.oracle.graal.python.nodes.BuiltinNames.DISPLAYHOOK;
|
71 | 71 | import static com.oracle.graal.python.nodes.BuiltinNames.EXCEPTHOOK;
|
72 |
| -import static com.oracle.graal.python.nodes.BuiltinNames.EXIT; |
73 | 72 | import static com.oracle.graal.python.nodes.BuiltinNames.PYTHONBREAKPOINT;
|
74 | 73 | import static com.oracle.graal.python.nodes.BuiltinNames.STDERR;
|
75 | 74 | import static com.oracle.graal.python.nodes.BuiltinNames.STDIN;
|
|
87 | 86 | import static com.oracle.graal.python.nodes.ErrorMessages.REC_LIMIT_GREATER_THAN_1;
|
88 | 87 | import static com.oracle.graal.python.nodes.ErrorMessages.S_EXPECTED_GOT_P;
|
89 | 88 | import static com.oracle.graal.python.nodes.ErrorMessages.WARN_CANNOT_RUN_PDB_YET;
|
| 89 | +import static com.oracle.graal.python.nodes.ErrorMessages.WARN_DEPRECTATED_SYS_CHECKINTERVAL; |
90 | 90 | import static com.oracle.graal.python.nodes.ErrorMessages.WARN_IGNORE_UNIMPORTABLE_BREAKPOINT_S;
|
91 | 91 | import static com.oracle.graal.python.nodes.SpecialAttributeNames.__;
|
92 | 92 | import static com.oracle.graal.python.nodes.SpecialAttributeNames.__MODULE__;
|
|
105 | 105 |
|
106 | 106 | import com.oracle.graal.python.lib.PyFloatCheckExactNode;
|
107 | 107 | import com.oracle.graal.python.lib.PyLongAsIntNode;
|
108 |
| -import com.oracle.graal.python.runtime.exception.PythonExitException; |
109 | 108 | import org.graalvm.nativeimage.ImageInfo;
|
110 | 109 |
|
111 | 110 | import com.oracle.graal.python.PythonLanguage;
|
|
164 | 163 | import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
|
165 | 164 | import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
|
166 | 165 | import com.oracle.graal.python.nodes.function.builtins.PythonClinicBuiltinNode;
|
167 |
| -import com.oracle.graal.python.nodes.function.builtins.PythonVarargsBuiltinNode; |
168 | 166 | import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
|
169 | 167 | import com.oracle.graal.python.nodes.object.GetClassNode;
|
170 | 168 | import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
|
@@ -1442,4 +1440,47 @@ Object setRecLim(VirtualFrame frame, @SuppressWarnings("unused") PythonModule sy
|
1442 | 1440 | }
|
1443 | 1441 | }
|
1444 | 1442 |
|
| 1443 | + @Builtin(name = "getcheckinterval", minNumOfPositionalArgs = 1, declaresExplicitSelf = true, doc = "getcheckinterval($module, /)\n" + |
| 1444 | + "--\n" + |
| 1445 | + "\n" + |
| 1446 | + "Return the current check interval; see sys.setcheckinterval().") |
| 1447 | + @GenerateNodeFactory |
| 1448 | + abstract static class GetCheckIntervalNode extends PythonBuiltinNode { |
| 1449 | + @Specialization |
| 1450 | + Object getCheckInterval(VirtualFrame frame, @SuppressWarnings("unused") PythonModule sys, |
| 1451 | + @Cached WarningsModuleBuiltins.WarnNode warnNode) { |
| 1452 | + warnNode.warnFormat(frame, DeprecationWarning, WARN_DEPRECTATED_SYS_CHECKINTERVAL); |
| 1453 | + return getContext().getSysModuleState().getCheckInterval(); |
| 1454 | + } |
| 1455 | + } |
| 1456 | + |
| 1457 | + @Builtin(name = "setcheckinterval", minNumOfPositionalArgs = 2, declaresExplicitSelf = true, doc = "setcheckinterval($module, n, /)\n" + |
| 1458 | + "--\n" + |
| 1459 | + "\n" + |
| 1460 | + "Set the async event check interval to n instructions.\n" + |
| 1461 | + "\n" + |
| 1462 | + "This tells the Python interpreter to check for asynchronous events\n" + |
| 1463 | + "every n instructions.\n" + |
| 1464 | + "\n" + |
| 1465 | + "This also affects how often thread switches occur.") |
| 1466 | + @GenerateNodeFactory |
| 1467 | + abstract static class SetCheckIntervalNode extends PythonBuiltinNode { |
| 1468 | + @Specialization |
| 1469 | + Object setCheckInterval(VirtualFrame frame, @SuppressWarnings("unused") PythonModule sys, Object arg, |
| 1470 | + @Cached WarningsModuleBuiltins.WarnNode warnNode, |
| 1471 | + @Cached PyLongAsIntNode longAsIntNode, |
| 1472 | + @Cached PyFloatCheckExactNode floatCheckExactNode) { |
| 1473 | + if (floatCheckExactNode.execute(arg)) { |
| 1474 | + throw raise(TypeError, S_EXPECTED_GOT_P, "integer", arg); |
| 1475 | + } |
| 1476 | + |
| 1477 | + try { |
| 1478 | + final int n = longAsIntNode.execute(frame, arg); |
| 1479 | + warnNode.warnFormat(frame, DeprecationWarning, WARN_DEPRECTATED_SYS_CHECKINTERVAL); |
| 1480 | + getContext().getSysModuleState().setCheckInterval(n); |
| 1481 | + } catch (PException ignore) { |
| 1482 | + } |
| 1483 | + return PNone.NONE; |
| 1484 | + } |
| 1485 | + } |
1445 | 1486 | }
|
0 commit comments