-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
222d048
commit a8008de
Showing
8 changed files
with
252 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/test/java/org/jpy/fixtures/MultiThreadedEvalTestFixture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.jpy.fixtures; | ||
|
||
import org.jpy.PyInputMode; | ||
import org.jpy.PyLib; | ||
import org.jpy.PyObject; | ||
|
||
import java.util.List; | ||
|
||
public class MultiThreadedEvalTestFixture { | ||
|
||
public static void expression(String expression, int numThreads) { | ||
PyObject globals = PyLib.getCurrentGlobals(); | ||
PyObject locals = PyLib.getCurrentLocals(); | ||
|
||
List<Thread> threads = new java.util.ArrayList<>(); | ||
for (int i = 0; i < numThreads; i++) { | ||
threads.add(new Thread(() -> { | ||
PyObject.executeCode(expression, PyInputMode.EXPRESSION, globals, locals); | ||
})); | ||
} | ||
for (Thread thread : threads) { | ||
thread.start(); | ||
} | ||
for (Thread thread : threads) { | ||
try { | ||
thread.join(); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
|
||
public static void script(String expression, int numThreads) { | ||
List<Thread> threads = new java.util.ArrayList<>(); | ||
PyObject globals = PyLib.getCurrentGlobals(); | ||
PyObject locals = PyLib.getCurrentLocals(); | ||
for (int i = 0; i < numThreads; i++) { | ||
threads.add(new Thread(() -> { | ||
PyObject.executeCode(expression, PyInputMode.SCRIPT, globals, locals); | ||
})); | ||
} | ||
for (Thread thread : threads) { | ||
thread.start(); | ||
} | ||
for (Thread thread : threads) { | ||
try { | ||
thread.join(); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.