python.exe crash and ctypes use

W

waldek

Hi,

I have module A.py and B.dll which exports C functions by cdecl_

In A.py I pass callback (py callable) to dll. Next, thread inside dll
simply calls my callback (in a loop). After few secs I got crash of
python.exe.

How to debug it?

I'm using winxp and py 2.5.2


===========================
def mycallback(data, size)
return 0

CBFUNC = CFUNCTYPE(c_int,POINTER(c_int), c_int)
dll = cdll.mydll

if dll.RegisterCallback(CBFUNC(mycallback)) != 0:
print "Error."
===========================
 
D

Diez B. Roggisch

waldek said:
Hi,

I have module A.py and B.dll which exports C functions by cdecl_

In A.py I pass callback (py callable) to dll. Next, thread inside dll
simply calls my callback (in a loop). After few secs I got crash of
python.exe.

How to debug it?

I'm using winxp and py 2.5.2


===========================
def mycallback(data, size)
return 0

CBFUNC = CFUNCTYPE(c_int,POINTER(c_int), c_int)
dll = cdll.mydll

if dll.RegisterCallback(CBFUNC(mycallback)) != 0:
print "Error."
===========================

Attach a debugger of choice to your python-process, and see what happens.

Diez
 
T

Thomas Heller

waldek said:
Hi,

I have module A.py and B.dll which exports C functions by cdecl_

In A.py I pass callback (py callable) to dll. Next, thread inside dll
simply calls my callback (in a loop). After few secs I got crash of
python.exe.

How to debug it?

I'm using winxp and py 2.5.2


===========================
def mycallback(data, size)
return 0

CBFUNC = CFUNCTYPE(c_int,POINTER(c_int), c_int)
dll = cdll.mydll

if dll.RegisterCallback(CBFUNC(mycallback)) != 0:
print "Error."
===========================

You need the callback function instance - what the CBFUNC(mycallback)
call returns - alive as long as some C code is calling it.
If you don't sooner or later the Python garbage collector will
free it since it seems to be no longer used. ctypes does NOT keep
the callback function alive itself.

Thomas
 
W

waldek

waldek schrieb:











You need the callback function instance - what the CBFUNC(mycallback)
call returns - alive as long as some C code is calling it.
If you don't sooner or later the Python garbage collector will
free it since it seems to be no longer used. ctypes does NOT keep
the callback function alive itself.

Thomas

In fact ctypes does not keep references to callback passed directly to
dll. Now it works.
Thanks Thomas.

Waldek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top