Fatal Python error using ctypes & python exceptions



Hi Everyone,
I've created a 'C' dll that is accessed via ctypes library containing
a bunch of functions. I've successfully been able to use the
functions. However, I would like to throw python exceptions from some
of them.

I throw them using: ::PyErr_SetString(::PyExc_RuntimeError,
theErrorString);

I crash the console when this function is invoked in the 'C' domain. I
get an error stating:

Fatal Python error: PyThreadState_Get: no current thread

when the calling code in python is:

try:
cdll.MyDll.ThrowingFunction()
except:
print "An error has occurred"

The dll is just a plain win32 'C' dll, built with an MS compiler. How
do I throw python exceptions correctly? Is there some kind of "init"
function that needs to be called?

Any help much appreciated.

Thanks,
Martin

.



Relevant Pages

  • Re: Could not load file or assembly
    ... If my calling code is a WinForms app, this code works as long as the DLL is ... even if the relevant dll is in the bin directory of the ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: My XP pro system with 1GB ram is excruciatingly slow (explorer
    ... since I disable the .dll however. ... After looking about nls files, they seem to be language related, and no ... I took a look at process explorer and saw that I too had those files. ... sortkey.nls as well as a bunch of index.dats. ...
    (microsoft.public.windowsxp.perform_maintain)
  • Re: Protecting against type mismatch errors
    ... but the code would be in a DLL and the class would be called from Word ... so there's no possibility of controlling the calling code. ... other than by calling it from a Word template that I am supplying. ... Even tho the VBA project in that template will be password protected, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: My XP pro system with 1GB ram is excruciatingly slow (explorer
    ... an Ewido Anti-Spyware .dll seems to have helped ... It's possible that it's just an artifact of re-booting, ... sortkey.nls as well as a bunch of index.dats. ...
    (microsoft.public.windowsxp.perform_maintain)
  • Re: Coding a PHP5 extension with Visual Studio .NET
    ... The stuff I've seen is for PHP4 and seems to require a ... > bunch of Unix tools to operate (not a "show stopper", ... So if you are targetting the windows platform, why create a dll? ...
    (comp.lang.php)