[Python-Dev] The zombi thread of the Tcl library

Victor Stinner victor.stinner at haypocalc.com
Wed May 4 10:58:42 CEST 2011


Hi,

I have a question: would it be possible to mask all signals in the Tcl
thread? To understand the question, let's see the context...

I'm working on signals, especially on pthread_sigmask(), and I'm trying
to understand test_signal failures.

test_signal fails if the _tkinter module is loaded, because _tkinter
loads the Tcl library which create a thread waiting events in select().
For example, "python -m test test_pydoc test_signal" fails, because
test_pydoc loads ALL Python modules. I opened an issue for test_pydoc:
http://bugs.python.org/issue11995

_tkinter.c contains the following code:
#if 0
    /* This was not a good idea; through <Destroy> bindings,
       Tcl_Finalize() may invoke Python code but at that point the
       interpreter and thread state have already been destroyed! */
    Py_AtExit(Tcl_Finalize);
#endif

Tcl_Finalize() exits the thread, but this function is never called in
Python. Anyway, it is not possible to unload a module implemented in C.

I would like to know if it would be possible to mask all signals in the
Tcl thread, or if Tcl supports/uses signals.

It is possible to mask all signals in the Tcl thread using:
----------
allsignals = range(1, signal.NSIG)
oldmask = signal.pthread_sigmask(signal.SIG_BLOCK, allsignals)
import _tkinter
signal.pthread_sigmask(signal.SIG_SETMASK, oldmask)
----------

I'm not asking the question for test_signal: I have a patch fixing
test_signal, even if the Tcl zombi thread is present (use pthread_kill()
to send the signal directly to the main thread).

(I wrote "zombi" thread because I was not aware that Tcl uses a thread,
nor that test_pydoc loads all modules. The thread is valid, alive, and
it's just a joke. The threads is more hidden than zombi.)

Victor



More information about the Python-Dev mailing list