|
42 | 42 |
|
43 | 43 | import static com.oracle.graal.python.nodes.StringLiterals.J_NATIVE;
|
44 | 44 | import static com.oracle.graal.python.nodes.StringLiterals.T_BASE_PREFIX;
|
| 45 | +import static com.oracle.graal.python.nodes.StringLiterals.J_MAX_CAPI_COPIES; |
45 | 46 | import static com.oracle.graal.python.nodes.StringLiterals.T_PREFIX;
|
46 | 47 | import static com.oracle.graal.python.util.PythonUtils.toTruffleStringUncached;
|
47 | 48 |
|
48 | 49 | import java.io.IOException;
|
49 | 50 | import java.util.concurrent.atomic.AtomicInteger;
|
50 | 51 |
|
| 52 | +import com.oracle.graal.python.PythonLanguage; |
51 | 53 | import com.oracle.graal.python.builtins.objects.cext.common.LoadCExtException.ApiInitException;
|
52 | 54 | import com.oracle.graal.python.builtins.objects.cext.common.LoadCExtException.ImportException;
|
53 | 55 | import com.oracle.graal.python.nodes.ErrorMessages;
|
|
58 | 60 | import com.oracle.graal.python.util.BiFunction;
|
59 | 61 | import com.oracle.truffle.api.TruffleFile;
|
60 | 62 | import com.oracle.truffle.api.TruffleLanguage.Env;
|
| 63 | +import com.oracle.truffle.api.TruffleLogger; |
61 | 64 |
|
62 | 65 | /**
|
63 | 66 | * Given a GraalPy virtual environment, this class helps prepare that environment so that multiple
|
|
67 | 70 | * guaranteed to work with the matching GraalPy version.
|
68 | 71 | */
|
69 | 72 | public final class NativeLibraryLocator {
|
70 |
| - private static final int MAX_CEXT_COPIES = 64; |
| 73 | + static final TruffleLogger LOGGER = PythonLanguage.getLogger("NativeLibraryLocator"); |
| 74 | + |
| 75 | + private static final int MAX_CEXT_COPIES = Integer.getInteger(J_MAX_CAPI_COPIES, 64); |
71 | 76 |
|
72 | 77 | /**
|
73 | 78 | * Bitset for which copied C extension to use when {@link PythonOptions#IsolateNativeModules} is
|
@@ -144,6 +149,11 @@ public void close() {
|
144 | 149 | * count}.
|
145 | 150 | */
|
146 | 151 | public static void replicate(TruffleFile venvDirectory, PythonContext context, int count) throws IOException, InterruptedException {
|
| 152 | + if (count > MAX_CEXT_COPIES) { |
| 153 | + LOGGER.warning(() -> String.format("The current limit for concurrent Python contexts accessing the Python C API is %d, " + |
| 154 | + "but we are preparing %d copies. The extra copies will only be used if a different value " + |
| 155 | + "of the system property %s is set.", MAX_CEXT_COPIES, count, J_MAX_CAPI_COPIES)); |
| 156 | + } |
147 | 157 | String suffix = context.getSoAbi().toJavaStringUncached();
|
148 | 158 | TruffleFile capiLibrary = context.getPublicTruffleFileRelaxed(context.getCAPIHome()).resolve(PythonContext.getSupportLibName("python-" + J_NATIVE));
|
149 | 159 | try {
|
|
0 commit comments