mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
Cleanup from patch #683257:
Add missing INCREFs and re-indent returns to be consistent. Add \n\ for lines in docstring Add a pathetic test Add docs
This commit is contained in:
parent
c4f4ca91e1
commit
2294c0d4ec
3 changed files with 46 additions and 4 deletions
|
@ -106,6 +106,19 @@ the process of completing its import (and the imports, if any,
|
||||||
triggered by that).
|
triggered by that).
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
|
\begin{funcdesc}{acquire_lock}{}
|
||||||
|
Acquires the interpreter's import lock for the current thread. This lock
|
||||||
|
should be used by import hooks to ensure thread-safety when importing modules.
|
||||||
|
On platforms without threads, this function does nothing.
|
||||||
|
\versionadded{2.3}
|
||||||
|
\end{funcdesc}
|
||||||
|
|
||||||
|
\begin{funcdesc}{release_lock}{}
|
||||||
|
Release the interpreter's import lock.
|
||||||
|
On platforms without threads, this function does nothing.
|
||||||
|
\versionadded{2.3}
|
||||||
|
\end{funcdesc}
|
||||||
|
|
||||||
The following constants with integer values, defined in this module,
|
The following constants with integer values, defined in this module,
|
||||||
are used to indicate the search result of \function{find_module()}.
|
are used to indicate the search result of \function{find_module()}.
|
||||||
|
|
||||||
|
|
26
Lib/test/test_imp.py
Normal file
26
Lib/test/test_imp.py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
|
||||||
|
import imp
|
||||||
|
import unittest
|
||||||
|
from test_support import TestFailed
|
||||||
|
|
||||||
|
class ImpLock(unittest.TestCase):
|
||||||
|
|
||||||
|
# XXX this test is woefully inadequate, please fix me
|
||||||
|
def testLock(self):
|
||||||
|
LOOPS = 50
|
||||||
|
for i in range(LOOPS):
|
||||||
|
imp.acquire_lock()
|
||||||
|
for i in range(LOOPS):
|
||||||
|
imp.release_lock()
|
||||||
|
|
||||||
|
for i in range(LOOPS):
|
||||||
|
try:
|
||||||
|
imp.release_lock()
|
||||||
|
except RuntimeError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
raise TestFailed, \
|
||||||
|
"release_lock() without lock should raise RuntimeError"
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
test_support.run_unittest(ImpLock)
|
|
@ -305,7 +305,8 @@ imp_acquire_lock(PyObject *self, PyObject *args)
|
||||||
#ifdef WITH_THREAD
|
#ifdef WITH_THREAD
|
||||||
lock_import();
|
lock_import();
|
||||||
#endif
|
#endif
|
||||||
return Py_None;
|
Py_INCREF(Py_None);
|
||||||
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -320,7 +321,8 @@ imp_release_lock(PyObject *self, PyObject *args)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return Py_None;
|
Py_INCREF(Py_None);
|
||||||
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper for sys */
|
/* Helper for sys */
|
||||||
|
@ -2778,8 +2780,9 @@ On platforms without threads, return 0.");
|
||||||
|
|
||||||
PyDoc_STRVAR(doc_acquire_lock,
|
PyDoc_STRVAR(doc_acquire_lock,
|
||||||
"acquire_lock() -> None\n\
|
"acquire_lock() -> None\n\
|
||||||
Acquires the interpreter's import lock for the current thread. This lock
|
Acquires the interpreter's import lock for the current thread.\n\
|
||||||
should be used by import hooks to ensure thread-safety when importing modules.
|
This lock should be used by import hooks to ensure thread-safety\n\
|
||||||
|
when importing modules.\n\
|
||||||
On platforms without threads, this function does nothing.");
|
On platforms without threads, this function does nothing.");
|
||||||
|
|
||||||
PyDoc_STRVAR(doc_release_lock,
|
PyDoc_STRVAR(doc_release_lock,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue