364,111 Members | 2011 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

python, dlls, and multiple instances

Patrick Stinson
P: n/a
Patrick Stinson
Is it a correct to assume that you can use multiple instances of
python altogether if each is loaded from a separate dll? For instance,
if I write a couple of dll/so libs, and each has python statically
linked in, is it safe to assume that since dlls use their own address
space then each dll would have it's own GIL, and will therefore
coexist safely within the same app? This is correct across all
platforms, yes?

I ask because I will be writing an audio plugin that uses python both
for the gui and the audio thread. The audio thread must not be
blocked, and will also be set up as a restricted execution environment
to prevent the usual dangerous calls to open, socket, etc. The python
running in the application thread may be blocked and may do whatever
it wants.

I think my understanding is correct since our current dll
implementation statically links python, and I know that the host app
(Ableton Live) also uses python for it's scripting engine. This should
be fun, since I've wanted to write a recipe for using python in an
audio plugin GUIs for a while now.

Cheers!
Jun 27 '08 #1
Share this Question
Share on Google+
2 Replies


=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
P: n/a
=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
Is it a correct to assume that you can use multiple instances of
python altogether if each is loaded from a separate dll? For instance,
if I write a couple of dll/so libs, and each has python statically
linked in, is it safe to assume that since dlls use their own address
space
DLLs don't use their own address space. All DLLs of a single operating
system process use the same address space.

Different DLLs do use different portions of that address space.
then each dll would have it's own GIL, and will therefore
coexist safely within the same app? This is correct across all
platforms, yes?
No; it rather depends on the way the operating system resolves symbols.
On some systems (e.g. many Unix systems), there is only a single global
symbol table for the entire process. So when a shared library is loaded,
and needs to resolve its symbols (even the ones that it also defines
itself), it may end up finding the GIL in a different copy of the Python
interpreter, so they all share the GIL (even though there would have
been space for multiple GILs).

Regards,
Martin
Jun 27 '08 #2

Patrick Stinson
P: n/a
Patrick Stinson
ahh, ok. Looks like my fundamental understanding of how dlls work was
a little messed up. Thanks!

On Sun, Jun 1, 2008 at 10:42 AM, "Martin v. Löwis" <martin@v.loewis.dewrote:
>Is it a correct to assume that you can use multiple instances of
>python altogether if each is loaded from a separate dll? For instance,
>if I write a couple of dll/so libs, and each has python statically
>linked in, is it safe to assume that since dlls use their own address
>space
>
DLLs don't use their own address space. All DLLs of a single operating
system process use the same address space.
>
Different DLLs do use different portions of that address space.
>
>then each dll would have it's own GIL, and will therefore
>coexist safely within the same app? This is correct across all
>platforms, yes?
>
No; it rather depends on the way the operating system resolves symbols.
On some systems (e.g. many Unix systems), there is only a single global
symbol table for the entire process. So when a shared library is loaded,
and needs to resolve its symbols (even the ones that it also defines
itself), it may end up finding the GIL in a different copy of the Python
interpreter, so they all share the GIL (even though there would have
been space for multiple GILs).
>
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list
>
Jun 27 '08 #3

Post your reply

Help answer this question



Didn't find the answer to your Python question?

You can also browse similar questions: Python