Skip to content

Commit 60d4943

Browse files
committed
_thread builtin support controllable via expert mode level "python.WithThread" option
1 parent 2fd3d5c commit 60d4943

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ public final class PythonLanguage extends TruffleLanguage<PythonContext> {
103103
public static final int MICRO = 0;
104104
public static final String VERSION = MAJOR + "." + MINOR + "." + MICRO;
105105

106-
public static boolean WITH_THREADS = false;
107-
108106
public static final String MIME_TYPE = "text/x-python";
109107
public static final String EXTENSION = ".py";
110108

@@ -141,7 +139,7 @@ protected boolean patchContext(PythonContext context, Env newEnv) {
141139
@Override
142140
protected PythonContext createContext(Env env) {
143141
ensureHomeInOptions(env);
144-
Python3Core newCore = new Python3Core(new PythonParserImpl());
142+
Python3Core newCore = new Python3Core(new PythonParserImpl(), env);
145143
return new PythonContext(this, env, newCore);
146144
}
147145

@@ -491,7 +489,7 @@ protected boolean isThreadAccessAllowed(Thread thread, boolean singleThreaded) {
491489
if (singleThreaded) {
492490
return super.isThreadAccessAllowed(thread, singleThreaded);
493491
}
494-
return WITH_THREADS;
492+
return PythonOptions.isWithThread();
495493
}
496494

497495
@Override

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ private static final String[] initializeCoreFiles() {
227227

228228
private final PythonBuiltins[] builtins;
229229

230-
private static final PythonBuiltins[] initializeBuiltins() {
230+
private static final PythonBuiltins[] initializeBuiltins(Env env) {
231231
List<PythonBuiltins> builtins = new ArrayList<>(Arrays.asList(
232232
new BuiltinConstructors(),
233233
new BuiltinFunctions(),
@@ -330,7 +330,7 @@ private static final PythonBuiltins[] initializeBuiltins() {
330330
}
331331
}
332332
// threads
333-
if (PythonLanguage.WITH_THREADS) {
333+
if (env.getOptions().get(PythonOptions.WithThread)) {
334334
builtins.addAll(new ArrayList<>(Arrays.asList(
335335
new ThreadModuleBuiltins(),
336336
new ThreadBuiltins(),
@@ -361,9 +361,9 @@ private static final PythonBuiltins[] initializeBuiltins() {
361361

362362
private final PythonObjectFactory factory = PythonObjectFactory.create();
363363

364-
public Python3Core(PythonParser parser) {
364+
public Python3Core(PythonParser parser, Env env) {
365365
this.parser = parser;
366-
this.builtins = initializeBuiltins();
366+
this.builtins = initializeBuiltins(env);
367367
this.coreFiles = initializeCoreFiles();
368368
}
369369

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SysConfigModuleBuiltins.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
import com.oracle.graal.python.builtins.objects.dict.PDict;
5252
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
5353
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
54+
import com.oracle.graal.python.runtime.PythonCore;
55+
import com.oracle.graal.python.runtime.PythonOptions;
5456
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
5557
import com.oracle.truffle.api.dsl.NodeFactory;
5658
import com.oracle.truffle.api.dsl.Specialization;
@@ -62,8 +64,11 @@
6264
@CoreFunctions(defineModule = "_sysconfig")
6365
public class SysConfigModuleBuiltins extends PythonBuiltins {
6466
private final static Map<Object, Object> STATIC_CONFIG_OPTIONS = new HashMap<>();
65-
static {
66-
STATIC_CONFIG_OPTIONS.put("WITH_THREAD", PythonLanguage.WITH_THREADS ? 1 : 0);
67+
68+
@Override
69+
public void initialize(PythonCore core) {
70+
super.initialize(core);
71+
STATIC_CONFIG_OPTIONS.put("WITH_THREAD", PythonOptions.isWithThread() ? 1 : 0);
6772
}
6873

6974
@Override

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonOptions.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ private PythonOptions() {
8282
@Option(category = OptionCategory.EXPERT, help = "This option is set by the Python launcher to tell the language it can print exceptions directly") //
8383
public static final OptionKey<Boolean> AlwaysRunExcepthook = new OptionKey<>(false);
8484

85+
@Option(category = OptionCategory.EXPERT, help = "This option control builtin _thread module support") //
86+
public static final OptionKey<Boolean> WithThread = new OptionKey<>(false);
87+
8588
@Option(category = OptionCategory.USER, help = "This option makes reading from files return opaque objects. Imports can work with such data, " +
8689
"but all other access to the contents of the file is disabled, so the files are kept secret.") //
8790
public static final OptionKey<Boolean> OpaqueFilesystem = new OptionKey<>(false);
@@ -156,4 +159,8 @@ public static boolean useLazyString() {
156159
public static int getMinLazyStringLength() {
157160
return getOption(PythonLanguage.getContextRef().get(), MinLazyStringLength);
158161
}
162+
163+
public static boolean isWithThread() {
164+
return getOption(PythonLanguage.getContextRef().get(), WithThread);
165+
}
159166
}

0 commit comments

Comments
 (0)