473,406 Members | 2,336 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,406 software developers and data experts.

python.exe crash and ctypes use

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
3 2996
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 398 open ( +5) / 3334 closed (+19) / 3732 total (+24) Bugs : 904 open ( -4) / 6011 closed (+36) / 6915 total (+32) RFE : 222 open...
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 431 open ( +3) / 3425 closed ( +8) / 3856 total (+11) Bugs : 916 open (-23) / 6273 closed (+44) / 7189 total (+21) RFE : 244 open...
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 430 open ( -4) / 3447 closed (+17) / 3877 total (+13) Bugs : 922 open ( -7) / 6316 closed (+31) / 7238 total (+24) RFE : 245 open...
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 421 open ( -2) / 3549 closed (+10) / 3970 total ( +8) Bugs : 943 open (-17) / 6471 closed (+25) / 7414 total ( +8) RFE : 260 open...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.