Skip to content

Commit

Permalink
Turn off Python sub-interpreter tests (#26614)
Browse files Browse the repository at this point in the history
This PR turns off Python sub-interpreter tests. These tests have wildly
unpredictable output due to race conditions. This PR also adds a warning
to the docs warning users about this.

The unpredictable behavior is caused by race conditions when
creating/destroying sub-interpreters, see
#26615.

This PR has a few other nit cleanups.

[Reviewed by @lydia-duncan]
  • Loading branch information
jabraham17 authored Jan 29, 2025
2 parents dcfb40c + 050bb45 commit 6c78a52
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 18 deletions.
24 changes: 9 additions & 15 deletions modules/packages/Python.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
Using Multiple Interpreters
~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. warning::
Sub-interpreter support in Chapel is highly experimental and currently has
undefined behavior.
The most performant way to run Python code in parallel is to use multiple
sub-interpreters. Each sub-interpreter is isolated from the others with its
own GIL. This allows multiple threads to run Python code concurrently. Note
Expand All @@ -94,11 +99,8 @@
..
START_TEST
FILENAME: CoforallTestSub.chpl
NOEXEC
START_GOOD
Hello from a task
Hello from a task
Hello from a task
Hello from a task
END_GOOD
.. code-block:: chapel
Expand Down Expand Up @@ -135,17 +137,8 @@
..
START_TEST
FILENAME: TaskPrivateSubInterp.chpl
NOEXEC
START_GOOD
10
10
10
10
10
10
10
10
10
10
END_GOOD
.. code-block:: chapel
Expand Down Expand Up @@ -1241,7 +1234,8 @@ module Python {
/*
Returns the Chapel value of the object.
This is a shortcut for calling :proc:`~Interpreter.fromPython` on this object, however it does not consume the object.
This is a shortcut for calling :proc:`~Interpreter.fromPython` on this
object, however it does not consume the object.
*/
proc value(type value) throws {
// fromPython will decrement the reference count, so we need to increment it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use Time;
config const print = true;
config const time = false;
config const n = 10;
config const runSubInterp = false;

config const lambdaStr = "lambda x,: x + 1 if x % 2 != 0 else x";
proc makeEven(x: int): int do return if x % 2 != 0 then x+1 else x;
Expand Down Expand Up @@ -112,7 +113,7 @@ proc main() {
writeln("Parallel Python result: ", res);
}

{
if runSubInterp {
data = 1..#n;
var s = new stopwatch();
s.start();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
data: 1 2 3 4 5 6 7 8 9 10
Serial Python result: 2 2 4 4 6 6 8 8 10 10
Parallel Python result: 2 2 4 4 6 6 8 8 10 10
Parallel Python SubInterpreter result: 2 2 4 4 6 6 8 8 10 10
Serial Chapel result: 2 2 4 4 6 6 8 8 10 10
Parallel Chapel result: 2 2 4 4 6 6 8 8 10 10
Original file line number Diff line number Diff line change
@@ -1 +1 @@
feature request: ability to set override the global checkExceptions
feature request: ability to override the global checkExceptions
1 change: 1 addition & 0 deletions test/library/packages/Python/correctness/subInterp.noexec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sub interpreters are highly unstable
1 change: 1 addition & 0 deletions test/library/packages/Python/doc-examples/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.good
*.execopts
*.compopts
*.noexec
3 changes: 3 additions & 0 deletions test/library/packages/Python/doc-examples/CLEANFILES
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
*.chpl
*.good
*.execopts
*.compopts
*.noexec
13 changes: 13 additions & 0 deletions test/library/packages/Python/doc-examples/parse_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class TestCase:
good_file: File = field(default_factory=File)
compopts: typing.Optional[File] = None
execopts: typing.Optional[File] = None
noexec: bool = False

def write(self, directory: str):
self.test_file.write(directory)
Expand All @@ -47,6 +48,12 @@ def write(self, directory: str):
self.compopts.write(directory)
if self.execopts:
self.execopts.write(directory)
if self.noexec:
noexec_file = os.path.join(
directory, self.test_file.basename() + ".noexec"
)
with open(noexec_file, "w"):
pass


def parse(lines: typing.List[str]) -> typing.List[TestCase]:
Expand Down Expand Up @@ -133,6 +140,12 @@ def has_more():
cur_line += 1
continue

# set the noexec flag
if test and test_file and lines[cur_line].strip() == "NOEXEC":
test.noexec = True
cur_line += 1
continue

# skip the '.. code-block:: chapel'
if test and lines[cur_line].strip().startswith(
".. code-block:: chapel"
Expand Down

0 comments on commit 6c78a52

Please sign in to comment.