473,602 Members | 2,920 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.RegisterCal lback(CBFUNC(my callback)) != 0:
print "Error."
=============== ============
Jul 23 '08 #1
3 3009
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.RegisterCal lback(CBFUNC(my callback)) != 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.RegisterCal lback(CBFUNC(my callback)) != 0:
print "Error."
=============== ============
You need the callback function instance - what the CBFUNC(mycallba ck)
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.RegisterCal lback(CBFUNC(my callback)) != 0:
print "Error."
=============== ============

You need the callback function instance - what the CBFUNC(mycallba ck)
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
325
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 ( -1) / 231 closed ( +2) / 453 total ( +1) New / Reopened Patches ______________________
0
263
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 ( +4) / 240 closed ( +1) / 484 total ( +5) New / Reopened Patches ______________________
0
278
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) / 241 closed ( +1) / 486 total ( +1) New / Reopened Patches ______________________
0
324
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 ( +2) / 250 closed ( +1) / 510 total ( +3) New / Reopened Patches ______________________
0
7993
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7921
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8405
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8056
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8270
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6730
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5870
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5440
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
1256
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.