naive misuse?

J

johan2sson

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
 
J

johan2sson

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?

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

Thanks,
Johan
 
T

Tim Peters

[[email protected]]
[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).
 
S

Simon Forman

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

Thanks,
Johan

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,191
Latest member
BuyKetoBeez

Latest Threads

Top