473,789 Members | 2,679 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Running in Release or Debug version of the python interpreter?

Hi

I have to check wheter a .py script is run within the debug or the
release version of an embedded python interpreter (in short, wheter
python24_d.dll or python24.dll is in use).

long version: I'm using ctypes to load my own dll. There exists 2
version of this dll - a debug and a release version (where one is linked
against debug C runtime dll and the other to release C runtime dll). Now
I have to change the name of the dll I want to be loaded by ctypes...
But how can I find out which of the dll I have to load?!

Thanks in advance!
Raphael Zulliger
Jul 19 '05 #1
3 3294
Raphael Zulliger wrote:

long version: I'm using ctypes to load my own dll. There exists 2
version of this dll - a debug and a release version (where one is linked
against debug C runtime dll and the other to release C runtime dll). Now
I have to change the name of the dll I want to be loaded by ctypes...
But how can I find out which of the dll I have to load?!


calling GetModuleFileNa me (in kernel32.dll) on sys.dllhandle should give
you the name of the current Python DLL. something like this should work:

from ctypes import *
MAX_PATH = 500
filename = c_buffer(MAX_PA TH)
windll.kernel32 .GetModuleFileN ameA(sys.dllhan dle, filename, MAX_PATH)
filename = filename.value

</F>

Jul 19 '05 #2
Raphael Zulliger schrieb:
Hi

I have to check wheter a .py script is run within the debug or the
release version of an embedded python interpreter (in short, wheter
python24_d.dll or python24.dll is in use).

long version: I'm using ctypes to load my own dll. There exists 2
version of this dll - a debug and a release version (where one is linked
against debug C runtime dll and the other to release C runtime dll). Now
I have to change the name of the dll I want to be loaded by ctypes...
But how can I find out which of the dll I have to load?!

Thanks in advance!
Raphael Zulliger


You could use imp.get_suffixe s(). In a release build the returned list
will contain these entries
('.pyd', 'rb', 3), ('.dll', 'rb', 3)
in a debug build that will be
('_d.pyd', 'rb', 3), ('_d.dll', 'rb', 3)

Another way would be to look at the filename of any binary extension
module. _ctypes.__file_ _, for example: '.....\\_ctypes .pyd' vs.
'....\\_ctypes_ d.pyd'.

Thomas
Jul 19 '05 #3
Thanks for your answers!
I prefer the proposal of Thomas Heller by using a small helper function
like this:

def IsDebugVersionR unning():
import imp
for suffix in imp.get_suffixe s():
if suffix[0] == '_d.pyd':
return True
return False

This works well for me. The
_ctypes.__file_ _
trick didn't work for me - I guess I've done something wrong...

One more question: Under linux this doesn't seam to work - as there is
always returned '.so' (not '_d.so') at least in my tests. Are there no
debug/release version issues like on windows? doesn't import the
python2.4-dbg (debian) binary different modules than python2.4?

Raphael Zulliger

Thomas Heller wrote:
Raphael Zulliger schrieb:
Hi

I have to check wheter a .py script is run within the debug or the
release version of an embedded python interpreter (in short, wheter
python24_d.dll or python24.dll is in use).

long version: I'm using ctypes to load my own dll. There exists 2
version of this dll - a debug and a release version (where one is
linked against debug C runtime dll and the other to release C runtime
dll). Now
I have to change the name of the dll I want to be loaded by ctypes...
But how can I find out which of the dll I have to load?!

Thanks in advance!
Raphael Zulliger

You could use imp.get_suffixe s(). In a release build the returned list
will contain these entries
('.pyd', 'rb', 3), ('.dll', 'rb', 3)
in a debug build that will be
('_d.pyd', 'rb', 3), ('_d.dll', 'rb', 3)

Another way would be to look at the filename of any binary extension
module. _ctypes.__file_ _, for example: '.....\\_ctypes .pyd' vs.
'....\\_ctypes_ d.pyd'.

Thomas

Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1618
by: Stephen Kellett | last post by:
Hi Folks, We've been using Python embedded in an application for a while now, where the Python dll is PythonNN.dll, NN being the version number, such as Python24.dll. Recently it was pointed out to me that Python can run in a debug or release configuration and that you can specify this on the command line using -O and -OO.
10
1808
by: Carl Friedrich Bolz | last post by:
pypy-0.7.0: first PyPy-generated Python Implementations ============================================================== What was once just an idea between a few people discussing on some nested mailing list thread and in a pub became reality ... the PyPy development team is happy to announce its first public release of a fully translatable self contained Python implementation. The 0.7 release showcases the results of our efforts in the...
14
4345
by: Mark Dufour | last post by:
After nine months of hard work, I am proud to introduce my baby to the world: an experimental Python-to-C++ compiler. It can convert many Python programs into optimized C++ code, without any user intervention such as adding type declarations. It uses rather advanced static type inference techniques to deduce type information by itself. In addition, it determines whether deduced types may be parameterized, and if so, it generates...
0
1496
by: Carl Friedrich Bolz | last post by:
pypy-0.8.0: Translatable compiler/parser and some more speed ============================================================== The PyPy development team has been busy working and we've now packaged our latest improvements, completed work and new experiments as version 0.8.0, our third public release. The highlights of this third release of PyPy are: - Translatable parser and AST compiler. PyPy now integrates its own
41
2479
by: z | last post by:
I use Visual C 2005 to develop my programs. One in particular is crashing in very specific and hard to replicate situations, made worse by the fact it only crashes when run -outside- the dev - as an exe, not from the Debug option. If I try to launch the debug on the crashing program, it'll close before the debugger opens. Any suggestions as to how I should proceed? Thanks in advance.
1
1489
by: =?iso-8859-1?B?QW5kcuk=?= | last post by:
Crunchy 0.9 has been released. It is available at http://code.google.com/p/crunchy What is Crunchy? Crunchy is a an application that transforms html Python tutorials into interactive session viewed within a browser. We are not aware of any other application (in any language) similar to Crunchy. Currently Crunchy has only been fully tested with Firefox; we know that some browsers simply don't work with it. Crunchy should work with...
0
1095
by: =?iso-8859-1?B?QW5kcuk=?= | last post by:
Crunchy 0.9.1 has been released. It is available at http://code.google.com/p/crunchy Note that, if you have downloaded version 0.9 or version 0.9.0.1 you likely will not need to download this latest version. What is new since version 0.9? * Possibility to log selectively part of a session (as instructed by a tutorial *writer* such as a teacher who may want to evaluate
5
1363
by: llothar | last post by:
How can i find out if a selected python interpreter (i only know the path name under which i should start it) is a debug build? I tried sys.api_version, sys.platform, sys.version, sys.version_info and there is no difference between "python.exe" and "python_d.exe". I'm pretty sure the information is stored somewhere but i can't find it. Please help.
3
1884
by: R. Bernstein | last post by:
The next release of pydb will have the ability to go into ipython from inside the debugger. Sort of like how in ruby-debug you can go into irb :-) For ipython, this can be done pretty simply; there is an IPShellEmbed method which returns something you can call. But how could one do the same for the stock python interactive shell? To take this out of the realm of debugging. What you want to do is to write a python program that goes...
0
9666
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
9511
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
10408
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...
0
10199
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10139
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
9983
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...
1
7529
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
5417
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3700
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.