Skip to content

Commit a6a4dc8

Browse files
pitrouvstinner
authored andcommitted
bpo-31370: Remove support for threads-less builds (#3385)
* Remove Setup.config * Always define WITH_THREAD for compatibility.
1 parent 1f06a68 commit a6a4dc8

File tree

135 files changed

+2481
-4386
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+2481
-4386
lines changed

Doc/whatsnew/3.7.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ Build and C API Changes
344344
download a copy of 32-bit Python for this purpose. (Contributed by Zachary
345345
Ware in :issue:`30450`.)
346346

347+
* Support for building ``--without-threads`` is removed.
348+
(Contributed by Antoine Pitrou in :issue:`31370`.).
349+
347350

348351
Deprecated
349352
==========

Include/Python.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#error "Python's source code assumes C's unsigned char is an 8-bit type."
1919
#endif
2020

21-
#if defined(__sgi) && defined(WITH_THREAD) && !defined(_SGI_MP_SOURCE)
21+
#if defined(__sgi) && !defined(_SGI_MP_SOURCE)
2222
#define _SGI_MP_SOURCE
2323
#endif
2424

Include/ceval.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,6 @@ PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(struct _frame *f, int exc);
183183
PyAPI_FUNC(PyThreadState *) PyEval_SaveThread(void);
184184
PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *);
185185

186-
#ifdef WITH_THREAD
187-
188186
PyAPI_FUNC(int) PyEval_ThreadsInitialized(void);
189187
PyAPI_FUNC(void) PyEval_InitThreads(void);
190188
#ifndef Py_LIMITED_API
@@ -213,15 +211,6 @@ PyAPI_FUNC(Py_ssize_t) _PyEval_RequestCodeExtraIndex(freefunc);
213211
#define Py_END_ALLOW_THREADS PyEval_RestoreThread(_save); \
214212
}
215213

216-
#else /* !WITH_THREAD */
217-
218-
#define Py_BEGIN_ALLOW_THREADS {
219-
#define Py_BLOCK_THREADS
220-
#define Py_UNBLOCK_THREADS
221-
#define Py_END_ALLOW_THREADS }
222-
223-
#endif /* !WITH_THREAD */
224-
225214
#ifndef Py_LIMITED_API
226215
PyAPI_FUNC(int) _PyEval_SliceIndex(PyObject *, Py_ssize_t *);
227216
PyAPI_FUNC(int) _PyEval_SliceIndexNotNone(PyObject *, Py_ssize_t *);

Include/import.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,8 @@ PyAPI_FUNC(int) PyImport_ImportFrozenModule(
100100
);
101101

102102
#ifndef Py_LIMITED_API
103-
#ifdef WITH_THREAD
104103
PyAPI_FUNC(void) _PyImport_AcquireLock(void);
105104
PyAPI_FUNC(int) _PyImport_ReleaseLock(void);
106-
#else
107-
#define _PyImport_AcquireLock()
108-
#define _PyImport_ReleaseLock() 1
109-
#endif
110105

111106
PyAPI_FUNC(void) _PyImport_ReInitLock(void);
112107

Include/pyport.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,4 +797,12 @@ extern _invalid_parameter_handler _Py_silent_invalid_parameter_handler;
797797
#include <android/api-level.h>
798798
#endif
799799

800+
/* This macro used to tell whether Python was built with multithreading
801+
* enabled. Now multithreading is always enabled, but keep the macro
802+
* for compatibility.
803+
*/
804+
#ifndef WITH_THREAD
805+
#define WITH_THREAD
806+
#endif
807+
800808
#endif /* Py_PYPORT_H */

Include/pystate.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,10 @@ PyAPI_FUNC(void) PyThreadState_Delete(PyThreadState *);
218218
#ifndef Py_LIMITED_API
219219
PyAPI_FUNC(void) _PyThreadState_DeleteExcept(PyThreadState *tstate);
220220
#endif /* !Py_LIMITED_API */
221-
#ifdef WITH_THREAD
222221
PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);
223222
#ifndef Py_LIMITED_API
224223
PyAPI_FUNC(void) _PyGILState_Reinit(void);
225224
#endif /* !Py_LIMITED_API */
226-
#endif
227225

228226
/* Return the current thread state. The global interpreter lock must be held.
229227
* When the current thread state is NULL, this issues a fatal error (so that
@@ -257,7 +255,6 @@ typedef
257255
enum {PyGILState_LOCKED, PyGILState_UNLOCKED}
258256
PyGILState_STATE;
259257

260-
#ifdef WITH_THREAD
261258

262259
/* Ensure that the current thread is ready to call the Python
263260
C API, regardless of the current state of Python, or of its
@@ -319,7 +316,6 @@ PyAPI_FUNC(int) PyGILState_Check(void);
319316
PyAPI_FUNC(PyInterpreterState *) _PyGILState_GetInterpreterStateUnsafe(void);
320317
#endif
321318

322-
#endif /* #ifdef WITH_THREAD */
323319

324320
/* The implementation of sys._current_frames() Returns a dict mapping
325321
thread id to that thread's current frame.

Lib/_dummy_thread.py

Lines changed: 0 additions & 163 deletions
This file was deleted.

Lib/_pydecimal.py

Lines changed: 23 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -436,75 +436,34 @@ class FloatOperation(DecimalException, TypeError):
436436
# work for older Pythons. If threads are not part of the build, create a
437437
# mock threading object with threading.local() returning the module namespace.
438438

439-
try:
440-
import threading
441-
except ImportError:
442-
# Python was compiled without threads; create a mock object instead
443-
class MockThreading(object):
444-
def local(self, sys=sys):
445-
return sys.modules[__xname__]
446-
threading = MockThreading()
447-
del MockThreading
448-
449-
try:
450-
threading.local
451-
452-
except AttributeError:
453-
454-
# To fix reloading, force it to create a new context
455-
# Old contexts have different exceptions in their dicts, making problems.
456-
if hasattr(threading.current_thread(), '__decimal_context__'):
457-
del threading.current_thread().__decimal_context__
458-
459-
def setcontext(context):
460-
"""Set this thread's context to context."""
461-
if context in (DefaultContext, BasicContext, ExtendedContext):
462-
context = context.copy()
463-
context.clear_flags()
464-
threading.current_thread().__decimal_context__ = context
465-
466-
def getcontext():
467-
"""Returns this thread's context.
468-
469-
If this thread does not yet have a context, returns
470-
a new context and sets this thread's context.
471-
New contexts are copies of DefaultContext.
472-
"""
473-
try:
474-
return threading.current_thread().__decimal_context__
475-
except AttributeError:
476-
context = Context()
477-
threading.current_thread().__decimal_context__ = context
478-
return context
439+
import threading
479440

480-
else:
441+
local = threading.local()
442+
if hasattr(local, '__decimal_context__'):
443+
del local.__decimal_context__
481444

482-
local = threading.local()
483-
if hasattr(local, '__decimal_context__'):
484-
del local.__decimal_context__
445+
def getcontext(_local=local):
446+
"""Returns this thread's context.
485447
486-
def getcontext(_local=local):
487-
"""Returns this thread's context.
488-
489-
If this thread does not yet have a context, returns
490-
a new context and sets this thread's context.
491-
New contexts are copies of DefaultContext.
492-
"""
493-
try:
494-
return _local.__decimal_context__
495-
except AttributeError:
496-
context = Context()
497-
_local.__decimal_context__ = context
498-
return context
499-
500-
def setcontext(context, _local=local):
501-
"""Set this thread's context to context."""
502-
if context in (DefaultContext, BasicContext, ExtendedContext):
503-
context = context.copy()
504-
context.clear_flags()
448+
If this thread does not yet have a context, returns
449+
a new context and sets this thread's context.
450+
New contexts are copies of DefaultContext.
451+
"""
452+
try:
453+
return _local.__decimal_context__
454+
except AttributeError:
455+
context = Context()
505456
_local.__decimal_context__ = context
457+
return context
458+
459+
def setcontext(context, _local=local):
460+
"""Set this thread's context to context."""
461+
if context in (DefaultContext, BasicContext, ExtendedContext):
462+
context = context.copy()
463+
context.clear_flags()
464+
_local.__decimal_context__ = context
506465

507-
del threading, local # Don't contaminate the namespace
466+
del threading, local # Don't contaminate the namespace
508467

509468
def localcontext(ctx=None):
510469
"""Return a context manager for a copy of the supplied context

Lib/_pyio.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
import stat
1010
import sys
1111
# Import _thread instead of threading to reduce startup cost
12-
try:
13-
from _thread import allocate_lock as Lock
14-
except ImportError:
15-
from _dummy_thread import allocate_lock as Lock
12+
from _thread import allocate_lock as Lock
1613
if sys.platform in {'win32', 'cygwin'}:
1714
from msvcrt import setmode as _setmode
1815
else:

Lib/_strptime.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
from datetime import (date as datetime_date,
2020
timedelta as datetime_timedelta,
2121
timezone as datetime_timezone)
22-
try:
23-
from _thread import allocate_lock as _thread_allocate_lock
24-
except ImportError:
25-
from _dummy_thread import allocate_lock as _thread_allocate_lock
22+
from _thread import allocate_lock as _thread_allocate_lock
2623

2724
__all__ = []
2825

Lib/bz2.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414
import os
1515
import warnings
1616
import _compression
17-
18-
try:
19-
from threading import RLock
20-
except ImportError:
21-
from dummy_threading import RLock
17+
from threading import RLock
2218

2319
from _bz2 import BZ2Compressor, BZ2Decompressor
2420

0 commit comments

Comments
 (0)