Closes #15969: rename new API to have consistent names in the faulthandler module.

This commit is contained in:
Georg Brandl 2012-09-22 08:58:55 +02:00
parent ebf7f957d7
commit deb92b5b1b
4 changed files with 41 additions and 37 deletions

View File

@ -71,7 +71,7 @@ Fault handler state
Dump the tracebacks after a timeout Dump the tracebacks after a timeout
----------------------------------- -----------------------------------
.. function:: dump_tracebacks_later(timeout, repeat=False, file=sys.stderr, exit=False) .. function:: dump_traceback_later(timeout, repeat=False, file=sys.stderr, exit=False)
Dump the tracebacks of all threads, after a timeout of *timeout* seconds, or Dump the tracebacks of all threads, after a timeout of *timeout* seconds, or
every *timeout* seconds if *repeat* is ``True``. If *exit* is ``True``, call every *timeout* seconds if *repeat* is ``True``. If *exit* is ``True``, call
@ -84,9 +84,9 @@ Dump the tracebacks after a timeout
This function is implemented using a watchdog thread and therefore is not This function is implemented using a watchdog thread and therefore is not
available if Python is compiled with threads disabled. available if Python is compiled with threads disabled.
.. function:: cancel_dump_tracebacks_later() .. function:: cancel_dump_traceback_later()
Cancel the last call to :func:`dump_tracebacks_later`. Cancel the last call to :func:`dump_traceback_later`.
Dump the traceback on a user signal Dump the traceback on a user signal
@ -112,7 +112,7 @@ Dump the traceback on a user signal
File descriptor issue File descriptor issue
--------------------- ---------------------
:func:`enable`, :func:`dump_tracebacks_later` and :func:`register` keep the :func:`enable`, :func:`dump_traceback_later` and :func:`register` keep the
file descriptor of their *file* argument. If the file is closed and its file file descriptor of their *file* argument. If the file is closed and its file
descriptor is reused by a new file, or if :func:`os.dup2` is used to replace descriptor is reused by a new file, or if :func:`os.dup2` is used to replace
the file descriptor, the traceback will be written into a different file. Call the file descriptor, the traceback will be written into a different file. Call

View File

@ -407,7 +407,7 @@ Current thread XXX:
with temporary_filename() as filename: with temporary_filename() as filename:
self.check_dump_traceback_threads(filename) self.check_dump_traceback_threads(filename)
def _check_dump_tracebacks_later(self, repeat, cancel, filename, loops): def _check_dump_traceback_later(self, repeat, cancel, filename, loops):
""" """
Check how many times the traceback is written in timeout x 2.5 seconds, Check how many times the traceback is written in timeout x 2.5 seconds,
or timeout x 3.5 seconds if cancel is True: 1, 2 or 3 times depending or timeout x 3.5 seconds if cancel is True: 1, 2 or 3 times depending
@ -422,11 +422,11 @@ import time
def func(timeout, repeat, cancel, file, loops): def func(timeout, repeat, cancel, file, loops):
for loop in range(loops): for loop in range(loops):
faulthandler.dump_tracebacks_later(timeout, repeat=repeat, file=file) faulthandler.dump_traceback_later(timeout, repeat=repeat, file=file)
if cancel: if cancel:
faulthandler.cancel_dump_tracebacks_later() faulthandler.cancel_dump_traceback_later()
time.sleep(timeout * 5) time.sleep(timeout * 5)
faulthandler.cancel_dump_tracebacks_later() faulthandler.cancel_dump_traceback_later()
timeout = {timeout} timeout = {timeout}
repeat = {repeat} repeat = {repeat}
@ -462,9 +462,9 @@ if file is not None:
self.assertEqual(trace, '') self.assertEqual(trace, '')
self.assertEqual(exitcode, 0) self.assertEqual(exitcode, 0)
@unittest.skipIf(not hasattr(faulthandler, 'dump_tracebacks_later'), @unittest.skipIf(not hasattr(faulthandler, 'dump_traceback_later'),
'need faulthandler.dump_tracebacks_later()') 'need faulthandler.dump_traceback_later()')
def check_dump_tracebacks_later(self, repeat=False, cancel=False, def check_dump_traceback_later(self, repeat=False, cancel=False,
file=False, twice=False): file=False, twice=False):
if twice: if twice:
loops = 2 loops = 2
@ -472,25 +472,25 @@ if file is not None:
loops = 1 loops = 1
if file: if file:
with temporary_filename() as filename: with temporary_filename() as filename:
self._check_dump_tracebacks_later(repeat, cancel, self._check_dump_traceback_later(repeat, cancel,
filename, loops) filename, loops)
else: else:
self._check_dump_tracebacks_later(repeat, cancel, None, loops) self._check_dump_traceback_later(repeat, cancel, None, loops)
def test_dump_tracebacks_later(self): def test_dump_traceback_later(self):
self.check_dump_tracebacks_later() self.check_dump_traceback_later()
def test_dump_tracebacks_later_repeat(self): def test_dump_traceback_later_repeat(self):
self.check_dump_tracebacks_later(repeat=True) self.check_dump_traceback_later(repeat=True)
def test_dump_tracebacks_later_cancel(self): def test_dump_traceback_later_cancel(self):
self.check_dump_tracebacks_later(cancel=True) self.check_dump_traceback_later(cancel=True)
def test_dump_tracebacks_later_file(self): def test_dump_traceback_later_file(self):
self.check_dump_tracebacks_later(file=True) self.check_dump_traceback_later(file=True)
def test_dump_tracebacks_later_twice(self): def test_dump_traceback_later_twice(self):
self.check_dump_tracebacks_later(twice=True) self.check_dump_traceback_later(twice=True)
@unittest.skipIf(not hasattr(faulthandler, "register"), @unittest.skipIf(not hasattr(faulthandler, "register"),
"need faulthandler.register") "need faulthandler.register")

View File

@ -28,6 +28,10 @@ Extension Modules
- Issue #15977: Fix memory leak in Modules/_ssl.c when the function - Issue #15977: Fix memory leak in Modules/_ssl.c when the function
_set_npn_protocols() is called multiple times, thanks to Daniel Sommermann. _set_npn_protocols() is called multiple times, thanks to Daniel Sommermann.
- Issue #5969: faulthandler module: rename dump_tracebacks_later() to
dump_traceback_later() and cancel_dump_tracebacks_later() to
cancel_dump_traceback_later().
What's New in Python 3.3.0 Release Candidate 2? What's New in Python 3.3.0 Release Candidate 2?
=============================================== ===============================================

View File

@ -462,7 +462,7 @@ faulthandler_thread(void *unused)
} }
static void static void
cancel_dump_tracebacks_later(void) cancel_dump_traceback_later(void)
{ {
/* Notify cancellation */ /* Notify cancellation */
PyThread_release_lock(thread.cancel_event); PyThread_release_lock(thread.cancel_event);
@ -509,7 +509,7 @@ format_timeout(double timeout)
} }
static PyObject* static PyObject*
faulthandler_dump_tracebacks_later(PyObject *self, faulthandler_dump_traceback_later(PyObject *self,
PyObject *args, PyObject *kwargs) PyObject *args, PyObject *kwargs)
{ {
static char *kwlist[] = {"timeout", "repeat", "file", "exit", NULL}; static char *kwlist[] = {"timeout", "repeat", "file", "exit", NULL};
@ -524,7 +524,7 @@ faulthandler_dump_tracebacks_later(PyObject *self,
size_t header_len; size_t header_len;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"d|iOi:dump_tracebacks_later", kwlist, "d|iOi:dump_traceback_later", kwlist,
&timeout, &repeat, &file, &exit)) &timeout, &repeat, &file, &exit))
return NULL; return NULL;
if ((timeout * 1e6) >= (double) PY_TIMEOUT_MAX) { if ((timeout * 1e6) >= (double) PY_TIMEOUT_MAX) {
@ -552,7 +552,7 @@ faulthandler_dump_tracebacks_later(PyObject *self,
header_len = strlen(header); header_len = strlen(header);
/* Cancel previous thread, if running */ /* Cancel previous thread, if running */
cancel_dump_tracebacks_later(); cancel_dump_traceback_later();
Py_XDECREF(thread.file); Py_XDECREF(thread.file);
Py_INCREF(file); Py_INCREF(file);
@ -582,9 +582,9 @@ faulthandler_dump_tracebacks_later(PyObject *self,
} }
static PyObject* static PyObject*
faulthandler_cancel_dump_tracebacks_later_py(PyObject *self) faulthandler_cancel_dump_traceback_later_py(PyObject *self)
{ {
cancel_dump_tracebacks_later(); cancel_dump_traceback_later();
Py_RETURN_NONE; Py_RETURN_NONE;
} }
#endif /* FAULTHANDLER_LATER */ #endif /* FAULTHANDLER_LATER */
@ -970,16 +970,16 @@ static PyMethodDef module_methods[] = {
"dump the traceback of the current thread, or of all threads " "dump the traceback of the current thread, or of all threads "
"if all_threads is True, into file")}, "if all_threads is True, into file")},
#ifdef FAULTHANDLER_LATER #ifdef FAULTHANDLER_LATER
{"dump_tracebacks_later", {"dump_traceback_later",
(PyCFunction)faulthandler_dump_tracebacks_later, METH_VARARGS|METH_KEYWORDS, (PyCFunction)faulthandler_dump_traceback_later, METH_VARARGS|METH_KEYWORDS,
PyDoc_STR("dump_tracebacks_later(timeout, repeat=False, file=sys.stderrn, exit=False):\n" PyDoc_STR("dump_traceback_later(timeout, repeat=False, file=sys.stderrn, exit=False):\n"
"dump the traceback of all threads in timeout seconds,\n" "dump the traceback of all threads in timeout seconds,\n"
"or each timeout seconds if repeat is True. If exit is True, " "or each timeout seconds if repeat is True. If exit is True, "
"call _exit(1) which is not safe.")}, "call _exit(1) which is not safe.")},
{"cancel_dump_tracebacks_later", {"cancel_dump_traceback_later",
(PyCFunction)faulthandler_cancel_dump_tracebacks_later_py, METH_NOARGS, (PyCFunction)faulthandler_cancel_dump_traceback_later_py, METH_NOARGS,
PyDoc_STR("cancel_dump_tracebacks_later():\ncancel the previous call " PyDoc_STR("cancel_dump_traceback_later():\ncancel the previous call "
"to dump_tracebacks_later().")}, "to dump_traceback_later().")},
#endif #endif
#ifdef FAULTHANDLER_USER #ifdef FAULTHANDLER_USER
@ -1120,7 +1120,7 @@ void _PyFaulthandler_Fini(void)
#ifdef FAULTHANDLER_LATER #ifdef FAULTHANDLER_LATER
/* later */ /* later */
if (thread.cancel_event) { if (thread.cancel_event) {
cancel_dump_tracebacks_later(); cancel_dump_traceback_later();
PyThread_release_lock(thread.cancel_event); PyThread_release_lock(thread.cancel_event);
PyThread_free_lock(thread.cancel_event); PyThread_free_lock(thread.cancel_event);
thread.cancel_event = NULL; thread.cancel_event = NULL;