Py_AddPendingCall can't signal background threads!!!

Tim Peters tim.one at home.com
Thu Jan 4 23:28:21 EST 2001


[Warren Postma]
> ...
> I suppose I could actually have a Keyboard-Interrupt-Signal hack
> happen in Py_MakePendingCalls() to handle if a background thread
> was being told to "die", but thus far i have avoided making
> changes to my own embedded python 1.5.2 that would make it somehow
> incompatible with a stock Python system.
>
> However it appears that truly signalling a thread is not allowed
> in Python.

See the "feature request" PEP:

    http://python.sourceforge.net/peps/pep-0042.html

esp. the block starting:

    Killing a thread from another thread.  Or maybe sending
    signal.  Or maybe raising an asynchronous exception.

Because Python gets ported to every strange platform on earth, it relies on
a *very* small set of simple thread primitives.  Any native means of
signaling one thread from another is extremely platform-dependent (and often
not possible at all), so Python has avoided adding such a thing in the
absence of 147 platform experts volunteering to figure out how to accomplish
that on 147 different platforms.  Yes, I overstate the case <wink> -- but
the thrust is on-target.  For now, Python arranges that signals always get
delivered to "the main thread", just so that it's predictable.

If somebody volunteers to write a PEP and the code, I think Guido would
accept a patch to build a simple inter-thread exception mechanism on top of
the Py_MakePendingCalls hack.  We'd probably like to get a patch to add a
portable thread-local storage mechanism more than that, though, to simplify
implementing *all* the ways people would like to make Python's x-platform
thread facilities stronger.

it's-not-there-now-just-because-it-isn't-ly y'rs  - tim





More information about the Python-list mailing list