summaryrefslogtreecommitdiff
path: root/Include/import.h
diff options
context:
space:
mode:
authorThomas Wouters <thomas@python.org>2009-09-16 19:55:54 +0000
committerThomas Wouters <thomas@python.org>2009-09-16 19:55:54 +0000
commitd0b84ab78a79025c86218283045c1af0522fb875 (patch)
treef65ba5bf923ba824204c1fd228383220cc60dfaa /Include/import.h
parentde8bbf972708a3d615d4e2215dece94795385d8e (diff)
downloadcpython-d0b84ab78a79025c86218283045c1af0522fb875.tar.gz
Fix issue #1590864, multiple threads and fork() can cause deadlocks, by
acquiring the import lock around fork() calls. This prevents other threads from having that lock while the fork happens, and is the recommended way of dealing with such issues. There are two other locks we care about, the GIL and the Thread Local Storage lock. The GIL is obviously held when calling Python functions like os.fork(), and the TLS lock is explicitly reallocated instead, while also deleting now-orphaned TLS data. This only fixes calls to os.fork(), not extension modules or embedding programs calling C's fork() directly. Solving that requires a new set of API functions, and possibly a rewrite of the Python/thread_*.c mess. Add a warning explaining the problem to the documentation in the mean time. This also changes behaviour a little on AIX. Before, AIX (but only AIX) was getting the import lock reallocated, seemingly to avoid this very same problem. This is not the right approach, because the import lock is a re-entrant one, and reallocating would do the wrong thing when forking while holding the import lock. Will backport to 2.6, minus the tiny AIX behaviour change.
Diffstat (limited to 'Include/import.h')
-rw-r--r--Include/import.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/Include/import.h b/Include/import.h
index a6e2857392..1b7fe0a73c 100644
--- a/Include/import.h
+++ b/Include/import.h
@@ -27,6 +27,14 @@ PyAPI_FUNC(PyObject *) PyImport_ReloadModule(PyObject *m);
PyAPI_FUNC(void) PyImport_Cleanup(void);
PyAPI_FUNC(int) PyImport_ImportFrozenModule(char *);
+#ifdef WITH_THREAD
+PyAPI_FUNC(void) _PyImport_AcquireLock(void);
+PyAPI_FUNC(int) _PyImport_ReleaseLock(void);
+#else
+#define _PyImport_AcquireLock()
+#define _PyImport_ReleaseLock() 1
+#endif
+
PyAPI_FUNC(struct filedescr *) _PyImport_FindModule(
const char *, PyObject *, char *, size_t, FILE **, PyObject **);
PyAPI_FUNC(int) _PyImport_IsScript(struct filedescr *);