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

Running in Release or Debug version of the python interpreter?

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.