By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,814 Members | 1,136 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,814 IT Pros & Developers. It's quick & easy.

raising an exception in one thread from an other. (PyThreadState_SetAsyncExc)

P: n/a
I have been playing a bit with PyThreadState_SetAsyncExc. Now the
documentation abouth this call states the following:

| Returns the number of thread states modified; if it returns a number
| greater than one, you're in trouble, and you should call it again with
| exc set to NULL to revert the effect.
Now I don't have trouble with it returning numbers greater that one.
However it does sometimes return zero. I have the impression this
happens when the thread in question has already finished. I have
two questions.

1) Should I call it again with exc set to NULL when it returned zero?

2) Would the following be a decent way to handle numbers returned
greater than one? (Note the following is just to illustrate
what I want to do, not functioning code)

def raise_in_thread(thread_id, exception):

Nr = PyThreadState_SetAsyncExc(thread_id, exception)
while Nr > 1:
PyThreadState_SetAsyncExc(thread_id, NULL)
Nr = PyThreadState_SetAsyncExc(thread_id, exception)
What this basically does is when a number greater than one
is returned go in a loop to cancel the effect wait a short
time and try again.

Antoon Pardon
Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.