By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,610 Members | 935 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,610 IT Pros & Developers. It's quick & easy.

python.exe crash and ctypes use

P: n/a
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."
===========================
Jul 23 '08 #1
Share this Question
Share on Google+
3 Replies

P: n/a
waldek wrote:
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
Jul 23 '08 #2

P: n/a
waldek schrieb:
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
Jul 23 '08 #3

P: n/a
On Jul 23, 4:39 pm, Thomas Heller <thel...@python.netwrote:
waldek schrieb:
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
In fact ctypes does not keep references to callback passed directly to
dll. Now it works.
Thanks Thomas.

Waldek
Jul 24 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.