Threads, signals, and fork

Mark Mitchell markm at cup.hp.com
Wed Jul 3 21:14:03 EDT 2002


Python 2.2 blocks signals in new threads:

	/* Mask all signals in the current thread before creating the new
	 * thread.  This causes the new thread to start with all signals
	 * blocked.
	 */
	sigfillset(&newmask);
	SET_THREAD_SIGMASK(SIG_BLOCK, &newmask, &oldmask);

That means that if the thread calls fork(), all signals are blocked in
the child process.

This is not necessarily what the programmer wanted.

The blocking of signals for new threads is justified in the
documentation for the signal module with the argument that since some
systems do not allow you to send signals to individual threads, Python
doesn't let you do it on any system.

That argument is fine as far as it goes -- but since Python doesn't
provide sigprocmask, there's no way to re-enable signals -- even for
child processes.

Thoughts?

--
Mark Mitchell
CodeSourcery, LLC
mark at codesourcery.com





More information about the Python-list mailing list