473,323 Members | 1,547 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,323 software developers and data experts.

Should I always call PyErr_Clear() when an exception occurs?

I've found that the code below will crash if I don't have the
PyErr_Clear() function call. Should I always call PyErr_Clear()? The
error message I get has to do with garbage collection -->

Exception exceptions.ImportError: 'No module named badmodule' in 'garbage collec
tion' ignored
Fatal Python error: unexpected exception during garbage collection

/* Code that fails if PyErr_Clear() is removed */
#include "python.h"

int main()
{
PyObject *pName, *pModule;
int i;

Py_Initialize();
for (i = 0 ; i < 30; i++) {
// First, import the module
pName = PyString_FromString("badmodule");
pModule = PyImport_Import(pName);
Py_DECREF(pName);
if (!pModule)
{
fprintf(stderr, "couldn't import badmodule\n");
PyErr_Clear();
}
}

Py_Finalize();
}

/* End code */

Thanks,
jw
Jul 18 '05 #1
0 1020

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

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
58
by: Jeff_Relf | last post by:
Hi Tom, You showed: << private const string PHONE_LIST = "495.1000__424.1111___(206)564-5555_1.800.325.3333"; static void Main( string args ) { foreach (string phoneNumber in Regex.Split...
4
by: Coot | last post by:
I've been running many tests of the Asynchronous Delegate technique and I find that although BeginInvoke() does queue the method delegate onto a worker thread, it always does so on the _same_...
5
by: Peter Steele | last post by:
We have an application that when it runs in the IDE in debug mode an unhandled exception is occurring in a system header file associated with STL stirngs. The actual statement that crashes is ...
5
by: ypul | last post by:
the code below given is connection class ... now I want to use the connection in another class , by using the getConnection method. where should I call con.dispose() ? in connection class or...
6
by: Paul | last post by:
Hello, The following code generates an exception error the *second* time it is called. Can anyone see what I'm doing wrong? There is a similar example in Wrox Professional VB.NET Page 289. ...
6
by: Scott Gravenhorst | last post by:
Windows XP SP3 My application is set to open a SaveFile dialog when an exit is requested. When I click the app's close button, the save dialog opens, but when I click to change the folder, the...
0
Frinavale
by: Frinavale | last post by:
I have a peculiar problem... Background: I have a function that I don't want the user to execute more than once while they are waiting for it to process; therefore, I disable all of the...
11
by: mathieu | last post by:
Hi there, I'd like to know if there is a general answer to the following question: when making a public interface that access a container should the function throw an exception when the element...
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...
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: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.