Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8454659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:05:03+00:00 2026-06-10T12:05:03+00:00

I’ve a simplest test case here: %module test %{ static char* MyExceptionName = _test.MyException;

  • 0

I’ve a simplest test case here:

%module test
%{

static char* MyExceptionName = "_test.MyException";
static PyObject* MyException = NULL;

%}

%inline %{

static PyObject* Foo()
{
    PyErr_SetNone(MyException);
    return NULL;
}

%}

%init
{
    MyException = PyErr_NewException(MyExceptionName, NULL, NULL);
}

Here’s the setup.py script:

from distutils.core import setup, Extension
setup(name="test", version="1.0",
    ext_modules = [Extension("_test", ["test_wrap.c"])])

When I build it and test it as follows, I get:

 swig -python -threads test.i
 python_d -c "import test; test.Foo()"
 Fatal Python error: PyThreadState_Get: no current thread

The traceback I got was

python27_d.dll!Py_FatalError(const char * msg=0x000000001e355a00)  Line 1677    C
python27_d.dll!PyThreadState_Get()  Line 330    C
python27_d.dll!PyErr_Restore(_object * type=0x00000000020d50b8, _object * value=0x0000000000000000, _object * traceback=0x0000000000000000)  Line 27 + 0x5 bytes    C
python27_d.dll!PyErr_SetObject(_object * exception=0x00000000020d50b8, _object * value=0x0000000000000000)  Line 58 C
python27_d.dll!PyErr_SetNone(_object * exception=0x00000000020d50b8)  Line 64   C
_test_d.pyd!Foo()  Line 2976    C

Environment:

  • Win 7 64 bit,
  • Python 2.7.3 (default, Aug 15 2012, 18:18:52) [MSC v.1500 64 bit (AMD64)] on win32
  • Swig 2.0.7
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T12:05:05+00:00Added an answer on June 10, 2026 at 12:05 pm

    The reason for the error, as it turns out is because when -threads is enabled via

    swig -threads -python test.i
    

    We get something like this (excess code has been redacted):

    PyObject *_wrap_Foo(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
      PyObject *resultobj = 0;
      PyObject *result = 0 ;
    
      if (!PyArg_ParseTuple(args,(char *)":Foo")) SWIG_fail;
      {
        SWIG_PYTHON_THREAD_BEGIN_ALLOW;
        result = (PyObject *)Foo();
        SWIG_PYTHON_THREAD_END_ALLOW;
      }
      resultobj = result;
      return resultobj;
    fail:
      return NULL;
    }
    
    static PyObject* Foo()
    {
        PyErr_SetNone(MyException);
        return NULL;
    }
    

    See, when Foo() is called, the global interpreter lock has already been released. Foo() should no longer make any Python API calls.

    The solution is to use SWIG_Python_SetErrorObj, which grabs the Global Interpreter Lock before calling Python C API.

    static PyObject* Foo()
    {
        SWIG_Python_SetErrorObj(MyException, Py_None);
        return NULL;
    }
    

    Another method is to use SWIG_PYTHON_THREAD_BEGIN_BLOCK; and SWIG_PYTHON_THREAD_END_BLOCK;

    static PyObject* Foo()
    {
        SWIG_PYTHON_THREAD_BEGIN_BLOCK; 
    
        PyErr_SetNone(MyException);
    
        SWIG_PYTHON_THREAD_END_BLOCK;
        return NULL;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.