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

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 3264
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 GetModuleFileName (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_PATH)
windll.kernel32.GetModuleFileNameA(sys.dllhandle, 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_suffixes(). 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 IsDebugVersionRunning():
import imp
for suffix in imp.get_suffixes():
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_suffixes(). 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
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...
10
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...
14
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...
0
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...
41
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...
1
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...
0
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...
5
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,...
3
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;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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.