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

PyGILState_Release + Python2.3 = Segmentation Fault

Hi,

Could someone tell me why my extension module works under Python 2.4, but
fails with Segmentation Fault under Python 2.3? Here is the stripped version:

================================================
#include <Python.h>

static PyObject *
test_gil(PyObject *self)
{
PyGILState_STATE gs;

Py_BEGIN_ALLOW_THREADS

gs = PyGILState_Ensure();

PyGILState_Release(gs);

Py_END_ALLOW_THREADS

Py_INCREF(Py_None);
return Py_None;
}

static PyMethodDef test_gil_methods[] = {
{"test_gil", (PyCFunction)test_gil, METH_NOARGS},
{NULL}
};

PyMODINIT_FUNC
init_test_gil(void) {
(void)Py_InitModule("_test_gil", test_gil_methods);
}
===============================================

I've tested it with Debian Sid and Ubuntu Breezy.

Thanks,
Kirill
Jan 31 '06 #1
1 2080

Kirill Simonov wrote:
Hi,

Could someone tell me why my extension module works under Python 2.4, but
fails with Segmentation Fault under Python 2.3? Here is the stripped version:


Maybe Python threads aren't initialized? Adding a call to
PyEval_InitThreads() stops the seg fault for me in Python 2.3 on
Debian:

#include <Python.h>

static PyObject *
test_gil(PyObject *self)
{
PyGILState_STATE gs;
Py_BEGIN_ALLOW_THREADS
gs = PyGILState_Ensure();
PyGILState_Release(gs);
Py_END_ALLOW_THREADS
Py_INCREF(Py_None);
return Py_None;
}
static PyMethodDef test_gil_methods[] = {
{"test_gil", (PyCFunction)test_gil, METH_NOARGS},
{NULL}
};
PyMODINIT_FUNC
init_test_gil(void) {

/* This added */
PyEval_InitThreads();

(void)Py_InitModule("_test_gil", test_gil_methods);
}

Feb 2 '06 #2

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

Similar topics

0
by: Xavier | last post by:
Greetings, While messing around with the "dl" module I ran into a segfault. *DO NOTE THAT THE FOLLOWING OCCURED ON 2 OF MY LINUX WORKSTATIONS* ------ # python -c 'import dl;...
3
by: Zheng Da | last post by:
Program received signal SIGSEGV, Segmentation fault. 0x40093343 in _int_malloc () from /lib/tls/libc.so.6 (gdb) bt #0 0x40093343 in _int_malloc () from /lib/tls/libc.so.6 #1 0x40094c54 in malloc...
5
by: Fra-it | last post by:
Hi everybody, I'm trying to make the following code running properly, but I can't get rid of the "SEGMENTATION FAULT" error message when executing. Reading some messages posted earlier, I...
18
by: Digital Puer | last post by:
Hi, I'm coming over from Java to C++, so please bear with me. In C++, is there a way for me to use exceptions to catch segmentation faults (e.g. when I access a location off the end of an array)?...
27
by: Paminu | last post by:
I have a wierd problem. In my main function I print "test" as the first thing. But if I run the call to node_alloc AFTER the printf call I get a segmentation fault and test is not printed! ...
1
by: geoffschmidt | last post by:
I'm trying to write an extension in C that delivers callbacks to Python. The C code starts several threads, and I'd like one of the new threads that is started to be able to deliver callbacks to...
7
by: pycraze | last post by:
I would like to ask a question. How do one handle the exception due to Segmentation fault due to Python ? Our bit operations and arithmetic manipulations are written in C and to some of our...
3
by: madunix | last post by:
My Server is suffering bad lag (High Utlization) I am running on that server Oracle10g with apache_1.3.35/ php-4.4.2 Web visitors retrieve data from the web by php calls through oci cobnnection...
0
by: mathieu | last post by:
Hello and happy new year folks, I am experiencing a seg fault while using the python interface to the VTK library (debian oldstable, python 2.3). The VTK library is wrapped by a custom mechanism...
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
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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.