diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-08-30 05:16:13 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-08-30 05:16:13 (GMT) |
commit | 692323488baf518117d3ede90189812723f39948 (patch) | |
tree | 8401474367a2c7684060b891da495cfb025e9bd5 /Python/import.c | |
parent | c41418751fcef0a42f336ba91871827b45d558a7 (diff) | |
download | cpython-692323488baf518117d3ede90189812723f39948.zip cpython-692323488baf518117d3ede90189812723f39948.tar.gz cpython-692323488baf518117d3ede90189812723f39948.tar.bz2 |
Add a new function imp.lock_held(), and use it to skip test_threaded_import
when that test is doomed to deadlock.
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Python/import.c b/Python/import.c index 5c2a9ad..52ad85e 100644 --- a/Python/import.c +++ b/Python/import.c @@ -181,6 +181,18 @@ unlock_import(void) #endif +static PyObject * +imp_lock_held(PyObject *self, PyObject *args) +{ + if (!PyArg_ParseTuple(args, ":lock_held")) + return NULL; +#ifdef WITH_THREAD + return PyInt_FromLong(import_lock_thread != -1); +#else + return PyInt_FromLong(0); +#endif +} + /* Helper for sys */ PyObject * @@ -2339,12 +2351,19 @@ Create a new module. Do not enter it in sys.modules.\n\ The module name must include the full package name, if any.\ "; +static char doc_lock_held[] = "\ +lock_held() -> 0 or 1\n\ +Return 1 if the import lock is currently held.\n\ +On platforms without threads, return 0.\ +"; + static PyMethodDef imp_methods[] = { {"find_module", imp_find_module, 1, doc_find_module}, {"get_magic", imp_get_magic, 1, doc_get_magic}, {"get_suffixes", imp_get_suffixes, 1, doc_get_suffixes}, {"load_module", imp_load_module, 1, doc_load_module}, {"new_module", imp_new_module, 1, doc_new_module}, + {"lock_held", imp_lock_held, 1, doc_lock_held}, /* The rest are obsolete */ {"get_frozen_object", imp_get_frozen_object, 1}, {"init_builtin", imp_init_builtin, 1}, |