@@ -127,6 +127,13 @@ public final class PythonLanguage extends TruffleLanguage<PythonContext> {
127
127
128
128
private static final Object [] CONTEXT_INSENSITIVE_SINGLETONS = new Object []{PNone .NONE , PNone .NO_VALUE , PEllipsis .INSTANCE , PNotImplemented .NOT_IMPLEMENTED };
129
129
130
+ /*
131
+ * We need to store this here, because the check is on the language and can
132
+ * come from a thread that has no context, but we enable or disable threads
133
+ * with a context option. So we store this here when a context is created.
134
+ */
135
+ private Boolean isWithThread = null ;
136
+
130
137
public static int getNumberOfSpecialSingletons () {
131
138
return CONTEXT_INSENSITIVE_SINGLETONS .length ;
132
139
}
@@ -159,14 +166,14 @@ protected void finalizeContext(PythonContext context) {
159
166
protected boolean areOptionsCompatible (OptionValues firstOptions , OptionValues newOptions ) {
160
167
// internal sources were marked during context initialization
161
168
return (firstOptions .get (PythonOptions .ExposeInternalSources ).equals (newOptions .get (PythonOptions .ExposeInternalSources )) &&
169
+ // we cache WithThread on the lanugage
170
+ firstOptions .get (PythonOptions .WithThread ).equals (newOptions .get (PythonOptions .WithThread )) &&
162
171
// we cache CatchAllExceptions hard on TryExceptNode
163
172
firstOptions .get (PythonOptions .CatchAllExceptions ).equals (newOptions .get (PythonOptions .CatchAllExceptions )));
164
173
}
165
174
166
175
private boolean areOptionsCompatibleWithPreinitializedContext (OptionValues firstOptions , OptionValues newOptions ) {
167
176
return (areOptionsCompatible (firstOptions , newOptions ) &&
168
- // we cache WithThread in SysConfigModuleBuiltins
169
- firstOptions .get (PythonOptions .WithThread ).equals (newOptions .get (PythonOptions .WithThread )) &&
170
177
// disabling TRegex has an effect on the _sre Python functions that are
171
178
// dynamically created
172
179
firstOptions .get (PythonOptions .WithTRegex ).equals (newOptions .get (PythonOptions .WithTRegex )));
@@ -186,6 +193,8 @@ protected boolean patchContext(PythonContext context, Env newEnv) {
186
193
187
194
@ Override
188
195
protected PythonContext createContext (Env env ) {
196
+ assert this .isWithThread == null || this .isWithThread == PythonOptions .isWithThread () : "conflicting thread options in the same language!" ;
197
+ this .isWithThread = PythonOptions .isWithThread (env );
189
198
ensureHomeInOptions (env );
190
199
Python3Core newCore = new Python3Core (new PythonParserImpl ());
191
200
return new PythonContext (this , env , newCore );
@@ -614,7 +623,7 @@ protected boolean isThreadAccessAllowed(Thread thread, boolean singleThreaded) {
614
623
if (singleThreaded ) {
615
624
return super .isThreadAccessAllowed (thread , singleThreaded );
616
625
}
617
- return PythonOptions . isWithThread () ;
626
+ return isWithThread ;
618
627
}
619
628
620
629
@ Override
0 commit comments