diff options
author | Victor Stinner <vstinner@python.org> | 2020-06-02 13:51:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-02 13:51:37 (GMT) |
commit | 26881c8fae3b67db3a01d335d3ae7356a29b433e (patch) | |
tree | 8cf867af2cd74581dc037a70e0549087d7e39fd3 /Python/import.c | |
parent | 297257f7bc198e2dc8e0866b539c73ff1a5cc588 (diff) | |
download | cpython-26881c8fae3b67db3a01d335d3ae7356a29b433e.zip cpython-26881c8fae3b67db3a01d335d3ae7356a29b433e.tar.gz cpython-26881c8fae3b67db3a01d335d3ae7356a29b433e.tar.bz2 |
PyOS_AfterFork_Child() uses PyStatus (GH-20596)
PyOS_AfterFork_Child() helper functions now return a PyStatus:
PyOS_AfterFork_Child() is now responsible to handle errors.
* Move _PySignal_AfterFork() to the internal C API
* Add #ifdef HAVE_FORK on _PyGILState_Reinit(), _PySignal_AfterFork()
and _PyInterpreterState_DeleteExceptMain().
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/Python/import.c b/Python/import.c index 0e2e7c3..35724fe 100644 --- a/Python/import.c +++ b/Python/import.c @@ -148,7 +148,7 @@ _PyImportZip_Init(PyThreadState *tstate) in different threads to return with a partially loaded module. These calls are serialized by the global interpreter lock. */ -static PyThread_type_lock import_lock = 0; +static PyThread_type_lock import_lock = NULL; static unsigned long import_lock_thread = PYTHREAD_INVALID_THREAD_ID; static int import_lock_level = 0; @@ -171,7 +171,7 @@ _PyImport_AcquireLock(void) !PyThread_acquire_lock(import_lock, 0)) { PyThreadState *tstate = PyEval_SaveThread(); - PyThread_acquire_lock(import_lock, 1); + PyThread_acquire_lock(import_lock, WAIT_LOCK); PyEval_RestoreThread(tstate); } assert(import_lock_level == 0); @@ -197,19 +197,19 @@ _PyImport_ReleaseLock(void) } #ifdef HAVE_FORK -/* This function is called from PyOS_AfterFork_Child to ensure that newly +/* This function is called from PyOS_AfterFork_Child() to ensure that newly created child processes do not share locks with the parent. We now acquire the import lock around fork() calls but on some platforms (Solaris 9 and earlier? see isue7242) that still left us with problems. */ - -void +PyStatus _PyImport_ReInitLock(void) { if (import_lock != NULL) { if (_PyThread_at_fork_reinit(&import_lock) < 0) { - _Py_FatalErrorFunc(__func__, "failed to create a new lock"); + return _PyStatus_ERR("failed to create a new lock"); } } + if (import_lock_level > 1) { /* Forked as a side effect of import */ unsigned long me = PyThread_get_thread_ident(); @@ -224,6 +224,7 @@ _PyImport_ReInitLock(void) import_lock_thread = PYTHREAD_INVALID_THREAD_ID; import_lock_level = 0; } + return _PyStatus_OK(); } #endif |