473,326 Members | 2,133 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,326 software developers and data experts.

Using PyThreadState_SetAsyncExc with PyEval_CallObject

I am attempting to raise an exception in a thread currently calling
PyEval_CallObject from another thread using PyThreadState_SetAsyncExc.
The PyEval_CallObject is currently calling of a function with looks
like

def fun() :
import time
count = 0
while 1:
count = count + 1
time.sleep( 1 )

PyThreadState_SetAsyncExc is returning 1 which I beleive means that it
found the thread id, but PyEval_CallObject is never returning. Here's
the code I'm using to raise the exception -

PyEval_AcquireLock ();
PyThreadState_Swap( thread_state );
PyObject * exc = PyErr_NewException( "exit_exc", 0, 0 );
int count = PyThreadState_SetAsyncExc( thread_id, exc );
std::cout << "PyThreadState_SetAsyncExc returned " << count <<
std::endl;
if (count > 1) {
std::cout << "PyThreadState_SetAsyncExc returned > 1, all
bets are off!" << std::endl;
PyThreadState_SetAsyncExc( thread_id, NULL );
}
Py_DECREF( exc );
PyThreadState_Swap(0);
PyEval_ReleaseLock();

I know that the 'party line' is for my thread to check to see if it
should cancel. In my application the functions running in the threads
are completely end user defined so there's no way I can guarantee that
it will check to see if it should exit. Is it possible to cancel a call
to PyEval_CallObject? This is running on Python 2.4/Win32 but any
solution will have to be portable to PPC Linux.

Thanks-

John

Aug 11 '05 #1
0 1290

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

Similar topics

0
by: Antoon Pardon | last post by:
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 |...
2
by: rawCoder | last post by:
Hi All, I have a *.cer file, a public key of some one and I want to encrypt some thing using this public key. Can someone point me to a sample code for Encrypting some file using...
1
by: Mike | last post by:
When trying to compile (using Visual Web Developer 2005 Express Beta; frameworkv2.0.50215 ) the source code below I get errors (listed below due to the use of ICallBackEventHandler. Ultimately I...
10
by: Christopher Benson-Manica | last post by:
Why can't I use a class destructor in a using declaration: using MyClass::~MyClass; ? -- Christopher Benson-Manica | I *should* know what I'm talking about - if I ataru(at)cyberspace.org ...
17
by: beliavsky | last post by:
Many of my C++ programs have the line using namespace std; but the "Accelerated C++" book of Koenig and Moo has many examples where the library names are included one at a time, for example ...
8
by: Petter Reinholdtsen | last post by:
I ran into a problem on HP-UX 11.00 the other day, where it refused to compile a program using 'using namespace std;' at the top. The reason seem to be that the compiler refuses to accept 'using...
0
by: Ralf Riemer | last post by:
Hi, I have some questions concerning the global interpreter lock: I am working with Windows XP Professional Version 5.1, Python version 2.4.1 and Microsoft Visual C++.Net Version 7.1. >From...
3
by: johan2sson | last post by:
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
1
by: iwl | last post by:
what is the nThreadId-Parameter of PyThreadState_SetAsyncExc? I try to implement a Terminate-Button in my C-Prog for my embedded Python, but its hard to find an example how to stop an...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.