473,385 Members | 1,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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)
sleep(0.1)
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
0 1416

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
by: Anthony Baxter | last post by:
On behalf of the Python development team and the Python community, I'm happy to announce the release of Python 2.3.1 (final). Python 2.3.1 is a pure bug fix release of Python 2.3, released in...
3
by: Calvin Spealman | last post by:
I was wondering if it was possible, now or with a patch, to do either of the following: 1) Cause another thread's most recent function, or a given function in a given thread, to yield its...
28
by: dcrespo | last post by:
Hi all, How can I get a raised exception from other thread that is in an imported module? For example: --------------- programA.py ---------------
6
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a...
0
by: Apu Nahasapeemapetilon | last post by:
Suggestions on cross-posting this issue would be appreciated. I've got a C# .NET DLL (CLR v1.1) that raises events into its container. When the container is a .NET application, raising the...
9
by: CuriousGeorge | last post by:
Can someone explain why this code DOES NOT raise a null reference exception? //////////////////////////// Program.cs ///////////////////////////////////////////// using System; using...
3
by: =?Utf-8?B?THVib21pcg==?= | last post by:
Hi, I have an app with the main thread and one additional thread. In the main thread I defined an event handler MyHandler, the function for raisin this event OnMyEvent and the function for...
28
by: Christoph Zwerschke | last post by:
What is the best way to re-raise any exception with a message supplemented with additional information (e.g. line number in a template)? Let's say for simplicity I just want to add "sorry" to every...
7
by: Brendon Costa | last post by:
Hi all, I have a small python project i am working on. Basically i always have two threads. A "Read" thread that sits in a loop reading a line at a time from some input (Usually stdin) and then...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.