diff --git a/modules/packages/Python.chpl b/modules/packages/Python.chpl index 8291789e01e8..6b2264c68e21 100644 --- a/modules/packages/Python.chpl +++ b/modules/packages/Python.chpl @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/test/library/packages/Python/correctness/compareIterationPatterns.chpl b/test/library/packages/Python/correctness/compareIterationPatterns.chpl index 6189855b7b27..77d301567c36 100644 --- a/test/library/packages/Python/correctness/compareIterationPatterns.chpl +++ b/test/library/packages/Python/correctness/compareIterationPatterns.chpl @@ -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; @@ -112,7 +113,7 @@ proc main() { writeln("Parallel Python result: ", res); } - { + if runSubInterp { data = 1..#n; var s = new stopwatch(); s.start(); diff --git a/test/library/packages/Python/correctness/compareIterationPatterns.good b/test/library/packages/Python/correctness/compareIterationPatterns.good index 693d2cfc2c62..b73a69445217 100644 --- a/test/library/packages/Python/correctness/compareIterationPatterns.good +++ b/test/library/packages/Python/correctness/compareIterationPatterns.good @@ -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 diff --git a/test/library/packages/Python/correctness/noExceptions.future b/test/library/packages/Python/correctness/noExceptions.future index f3bbdc0fa2c5..0fb01aa60986 100644 --- a/test/library/packages/Python/correctness/noExceptions.future +++ b/test/library/packages/Python/correctness/noExceptions.future @@ -1 +1 @@ -feature request: ability to set override the global checkExceptions +feature request: ability to override the global checkExceptions diff --git a/test/library/packages/Python/correctness/subInterp.noexec b/test/library/packages/Python/correctness/subInterp.noexec new file mode 100644 index 000000000000..f54abfa34527 --- /dev/null +++ b/test/library/packages/Python/correctness/subInterp.noexec @@ -0,0 +1 @@ +sub interpreters are highly unstable diff --git a/test/library/packages/Python/doc-examples/.gitignore b/test/library/packages/Python/doc-examples/.gitignore index 04ce433bf621..8f788a3503e5 100644 --- a/test/library/packages/Python/doc-examples/.gitignore +++ b/test/library/packages/Python/doc-examples/.gitignore @@ -2,3 +2,4 @@ *.good *.execopts *.compopts +*.noexec diff --git a/test/library/packages/Python/doc-examples/CLEANFILES b/test/library/packages/Python/doc-examples/CLEANFILES index f1f637982eb9..8f788a3503e5 100644 --- a/test/library/packages/Python/doc-examples/CLEANFILES +++ b/test/library/packages/Python/doc-examples/CLEANFILES @@ -1,2 +1,5 @@ *.chpl *.good +*.execopts +*.compopts +*.noexec diff --git a/test/library/packages/Python/doc-examples/parse_docs.py b/test/library/packages/Python/doc-examples/parse_docs.py index 419e7e420d19..1f5bc38afd9d 100644 --- a/test/library/packages/Python/doc-examples/parse_docs.py +++ b/test/library/packages/Python/doc-examples/parse_docs.py @@ -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) @@ -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]: @@ -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"