Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

naive misuse?

17 views
Skip to first unread message

johan...@gmail.com

unread,
Aug 28, 2006, 4:46:25 AM8/28/06
to
The documentation for PyThreadState_SetAsyncExc says "To prevent naive
misuse, you must write your own C extension to call this". Anyone care
to list a few examples of such naive misuse?

Johan

johan...@gmail.com

unread,
Aug 29, 2006, 4:09:02 AM8/29/06
to

No? I'll take that then as proof that it's impossible to misuse the
function.

Thanks,
Johan

Tim Peters

unread,
Aug 29, 2006, 5:01:46 AM8/29/06
to pytho...@python.org
[johan...@gmail.com]

>> The documentation for PyThreadState_SetAsyncExc says "To prevent naive
>> misuse, you must write your own C extension to call this". Anyone care
>> to list a few examples of such naive misuse?

[and again]


> No? I'll take that then as proof that it's impossible to misuse the
> function.

That's wise ;-) Stopping a thread asynchronously is in /general/ a
dangerous thing to do, and for obvious reasons. For example, perhaps
the victim thread is running in a library routine at the time the
asynch exception is raised, and getting forcibly ejected from the
normal control flow leaves a library-internal mutex locked forever.
Or perhaps a catch-all "finally:" clause in the library manages to
release the mutex, but leaves the internals in an inconsistent state.
Etc. The same kinds of potential disasters accout for why Java
deprecated its versions of this gimmick:

http://java.sun.com/j2se/1.3/docs/guide/misc/threadPrimitiveDeprecation.html

That said, you can invoke PyThreadState_SetAsyncExc() from Python
using the `ctypes` module (which will be included in 2.5, and is
available as an extension module for earlier Pythons).

Simon Forman

unread,
Aug 29, 2006, 12:33:40 PM8/29/06
to

I *was* going to say that if you didn't already know the answer to that
question then your use would almost certainly be naive. But I thought
that'd be more nasty than funny, so I bit my tongue.

~Simon

0 new messages